|
| 1 | +// import { useEffect } from 'react' |
| 2 | +// import branch, { BranchParams } from 'react-native-branch' |
| 3 | +// import { useDeeplink } from 'contexts/DeeplinkContext/DeeplinkContext' |
| 4 | +// import { DeepLink, DeepLinkOrigin } from 'contexts/DeeplinkContext/types' |
| 5 | +// import { useSelector } from 'react-redux' |
| 6 | +// import { selectDistinctID } from 'store/posthog' |
| 7 | +// import Logger from 'utils/Logger' |
| 8 | + |
| 9 | +// function handleBranchDeeplink( |
| 10 | +// setPendingDeepLink: (deepLink: DeepLink) => void, |
| 11 | +// params?: BranchParams | undefined |
| 12 | +// ): void { |
| 13 | +// if (params?.$deeplink_path) { |
| 14 | +// setPendingDeepLink({ |
| 15 | +// url: params.$deeplink_path as string, |
| 16 | +// origin: DeepLinkOrigin.ORIGIN_BRANCH |
| 17 | +// }) |
| 18 | +// } |
| 19 | +// } |
| 20 | + |
| 21 | +// export function useBranchDeeplinkObserver(): void { |
| 22 | +// const { setPendingDeepLink } = useDeeplink() |
| 23 | +// const distinctID = useSelector(selectDistinctID) |
| 24 | + |
| 25 | +// useEffect(() => { |
| 26 | +// branch.setRequestMetadata('$posthog_distinct_id', distinctID) |
| 27 | + |
| 28 | +// branch |
| 29 | +// .getLatestReferringParams() |
| 30 | +// .then((params?: BranchParams) => |
| 31 | +// handleBranchDeeplink(setPendingDeepLink, params) |
| 32 | +// ) |
| 33 | +// .catch(Logger.error) |
| 34 | + |
| 35 | +// const unsubscribe = branch.subscribe(({ params }) => |
| 36 | +// handleBranchDeeplink(setPendingDeepLink, params) |
| 37 | +// ) |
| 38 | + |
| 39 | +// return () => { |
| 40 | +// unsubscribe() |
| 41 | +// } |
| 42 | +// }, [distinctID, setPendingDeepLink]) |
| 43 | +// } |
0 commit comments