|
1 | 1 | # @swmansion/react-native-detour |
2 | 2 |
|
3 | | -sdk for handling deferred links |
| 3 | +SDK for handling deferred links in react native |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
| 7 | +npm: |
| 8 | + |
7 | 9 | ```sh |
8 | 10 | npm install @swmansion/react-native-detour |
9 | 11 | ``` |
10 | 12 |
|
| 13 | +yarn: |
| 14 | + |
| 15 | +```sh |
| 16 | +yarn add @swmansion/react-native-detour |
| 17 | +``` |
| 18 | + |
| 19 | +pnpm: |
| 20 | + |
| 21 | +```sh |
| 22 | +pnpm add @swmansion/react-native-detour |
| 23 | +``` |
| 24 | + |
| 25 | +bun: |
| 26 | + |
| 27 | +```sh |
| 28 | +bun add @swmansion/react-native-detour |
| 29 | +``` |
| 30 | + |
11 | 31 | #### You need to install additional dependencies |
12 | 32 |
|
| 33 | +npm: |
| 34 | + |
13 | 35 | ```sh |
14 | 36 | npm install expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application |
15 | 37 | ``` |
16 | 38 |
|
| 39 | +yarn: |
| 40 | + |
| 41 | +```sh |
| 42 | +yarn add expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application |
| 43 | +``` |
| 44 | + |
| 45 | +pnpm: |
| 46 | + |
| 47 | +```sh |
| 48 | +pnpm add expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application |
| 49 | +``` |
| 50 | + |
| 51 | +bun: |
| 52 | + |
| 53 | +```sh |
| 54 | +bun add expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application |
| 55 | +``` |
| 56 | + |
17 | 57 | ## Usage |
18 | 58 |
|
19 | 59 | #### Initialize provider in root of your app |
20 | 60 |
|
21 | 61 | ```js |
22 | 62 | import { DetourProvider, type Config } from '@swmansion/react-native-detour'; |
23 | 63 |
|
24 | | -export default function App() { |
25 | | - const config: Config = { |
26 | | - API_KEY: 'ssss-ssss-ssss', |
27 | | - appID: 'app-id-from-dashboard', |
28 | | - shouldUseClipboard: true, |
29 | | - }; |
| 64 | +const config: Config = { |
| 65 | + API_KEY: '<REPLACE_WITH_YOUR_API_KEY>', |
| 66 | + appID: '<REPLACE_WITH_APP_ID_FROM_PLATFORM>', |
| 67 | + shouldUseClipboard: true, |
| 68 | +}; |
| 69 | + |
| 70 | +export default function RootLayout() { |
30 | 71 |
|
31 | 72 | return( |
32 | 73 | <DetourProvider config={config}> |
33 | | - // rest of app content |
| 74 | + <RootNavigator /> |
34 | 75 | </DetourProvider>) |
35 | 76 | } |
36 | 77 | ``` |
37 | 78 |
|
38 | | -#### Use values from context |
| 79 | +#### Example usage with Expo Router |
39 | 80 |
|
40 | 81 | ```js |
41 | 82 | import { useDetourContext } from '@swmansion/react-native-detour'; |
| 83 | +import * as SplashScreen from 'expo-splash-screen'; |
| 84 | +import { Redirect, Stack } from 'expo-router'; |
| 85 | + |
| 86 | +SplashScreen.preventAutoHideAsync(); |
42 | 87 |
|
43 | | -// inside component |
44 | | -const { deferredLink, deferredLinkProcessed, route } = useDetourContext(); |
| 88 | +export function RootNavigator() { |
| 89 | + const { deferredLinkProcessed, deferredLink, route } = useDetourContext(); |
| 90 | + |
| 91 | + useEffect(() => { |
| 92 | + if (deferredLinkProcessed) { |
| 93 | + SplashScreen.hide(); |
| 94 | + } |
| 95 | + }, [deferredLinkProcessed]); |
| 96 | + |
| 97 | + if (!deferredLinkProcessed) { |
| 98 | + return null; |
| 99 | + } |
| 100 | + |
| 101 | + if (route) { |
| 102 | + return <Redirect href={route} />; |
| 103 | + } |
| 104 | + |
| 105 | + return <Stack />; |
| 106 | +} |
45 | 107 | ``` |
46 | 108 |
|
47 | 109 | ## Types |
@@ -97,16 +159,6 @@ export type DeferredLinkContext = { |
97 | 159 | }; |
98 | 160 | ``` |
99 | 161 |
|
100 | | -## Contributing |
101 | | - |
102 | | -- [Development workflow](CONTRIBUTING.md#development-workflow) |
103 | | -- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request) |
104 | | -- [Code of conduct](CODE_OF_CONDUCT.md) |
105 | | - |
106 | | -## License |
107 | | - |
108 | | -MIT |
109 | | - |
110 | 162 | --- |
111 | 163 |
|
112 | 164 | Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
0 commit comments