Skip to content

Commit c198955

Browse files
authored
docs: refactor example apps and installation guide (#67)
* docs: update readme for expo bare and router examples * refactor: improve clarity and conciseness of README examples * refactor: update readme deferred flow instructions * Revert "refactor: update readme deferred flow instructions" This reverts commit d703c8c. * docs: add deferred deep link example * docs: update example link handling descriptions * docs: add screenshots to expo-bare example * refactor: update app.json bundle identifiers and domain * docs: update screenshot paths in expo-bare example * docs: update expo bare example readme * docs: update bare expo readme example * docs: improve example readme descriptions * docs: update readme examples for detour * docs: update readme with new screenshots and clarify flow * refactor: extract LinkTestingCard component * docs: update expo-router native intent example * chore: update screenshots in intent example * docs: update react-navigation example screenshots and text * refactor: remove unused screenshot notes * docs: clarify link handling in examples * feat: add bare react native cli example * docs: add bare react native cli setup instructions * refactor: remove bare-react-native-cli example
1 parent 5c52474 commit c198955

72 files changed

Lines changed: 1873 additions & 761 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ npm install react-native-device-info
4444
>
4545
> For device info, install either `expo-device` or `react-native-device-info` — at least one is required. If your project already uses one of them, no extra installation is needed.
4646
47+
### Bare React Native CLI (without Expo)
48+
49+
Detour's peer dependencies are Expo Modules (they ship native code). In a bare React Native CLI project, add Expo Modules once and point Metro at `expo/metro-config`:
50+
51+
```sh
52+
npx install-expo-modules@latest
53+
npx expo install --fix
54+
```
55+
56+
```js
57+
// metro.config.js
58+
const { getDefaultConfig } = require("expo/metro-config");
59+
const { mergeConfig } = require("@react-native/metro-config");
60+
61+
module.exports = mergeConfig(getDefaultConfig(__dirname), {});
62+
```
63+
64+
Then rebuild — `DetourProvider` and the hooks work exactly as in the Expo examples.
65+
66+
See [Expo Modules setup](https://detour.swmansion.com/docs/sdk/react-native/sdk-installation#expo-modules-setup-react-native-cli) for the full walkthrough, and [build issues](https://detour.swmansion.com/docs/sdk/react-native/testing#bare-react-native-cli-build-issues) if you hit setup errors.
67+
4768
## Usage
4869

4970
Mount `DetourProvider` at the root of your app and configure it with your credentials. How you consume the resolved link depends on your navigation library.

examples/expo-bare/README.md

Lines changed: 123 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,129 @@
11
# Detour Expo Bare Example
22

3-
This example demonstrates a simple integration of `@swmansion/react-native-detour` in a React Native app.
3+
The most minimal integration of [`@swmansion/react-native-detour`](https://detour.swmansion.com/docs/sdk/react-native/sdk-installation) — no router, no navigation library. `DetourProvider` is initialized with SDK config and a single screen renders the raw `useDetourContext()` state. No router or navigation.
44

5-
## Scenario represented
5+
Use this as a quick SDK smoke test or as a base before adding your own routing.
66

7-
- `DetourProvider` is initialized with SDK config.
8-
- A single screen consumes `useDetourContext()`.
9-
- No router/navigation integration is implemented here.
10-
- The example is focused on exposing Detour link state.
7+
**Related examples:**
118

12-
## What this example is for
9+
- [`examples/expo-router`](../expo-router) — minimal Expo Router integration
10+
- [`examples/expo-router-advanced`](../expo-router-advanced) — auth-gated Expo Router flow
11+
- [`examples/react-navigation`](../react-navigation) — minimal React Navigation integration
1312

14-
- Quick SDK smoke test in isolation.
15-
- Verifying provider setup and context values.
16-
- Base starting point before adding your own navigation/deep-link routing logic.
13+
## Test flow
1714

18-
If you need more complex routing flows with a specific navigation library, check out the following examples:
15+
Launch the app — once the startup check completes, `isLinkProcessed` turns `true`. With no pending link, `type`, `url`, and `route` are empty.
1916

20-
- `examples/expo-router`
21-
- `examples/expo-router-advanced`
22-
- `examples/react-navigation`
17+
Trigger a Universal/App link (see [Triggering links](#triggering-links)) — `type`, `url`, and `route` populate with the resolved link data.
2318

24-
## Test flow
19+
To test the **deferred** case: follow the [Deferred deep link](#triggering-links) setup before installing. The deferred check only runs once - the SDK writes a persistent flag on first launch, so subsequent launches skip it. Reinstalling is needed to re-trigger the deferred path.
20+
21+
A **custom-scheme** link (`detour-expo-bare://details`) populates the same `type`, `url`, and `route` fields (with `type: scheme`) — see [Triggering links](#triggering-links).
22+
23+
<br>
24+
<img src="assets/screenshots/app-resolved.png" alt="Resolved Detour link state" width="50%"/>
25+
<br>
26+
27+
> _**Resolved link state**. The screen after a Detour link is resolved with `isLinkProcessed: true` and `type`, `url`, and `route` filled in._
28+
29+
## Set up Detour
30+
31+
You need a Detour account to register this app and generate its credentials. [Sign up](https://godetour.dev/auth/signup) and open the [Detour Dashboard](https://godetour.dev). If you run into issues during setup, the [Dashboard Walkthrough](https://detour.swmansion.com/docs/Fundamentals/dashboard) covers each step in detail.
32+
33+
### 1. Register the app
34+
35+
Create an organization and add a new app. Detour assigns it a base link URL of the form `https://<your-org>.godetour.link/<your-app-hash>` visible in **Link settings** section.
36+
37+
> In **Link settings**, the dashboard asks for a fallback Redirect URL to mark setup as complete. It only controls where **web** traffic lands — it has no effect on the deferred or Universal/App link flows these examples test, so it can be left empty or filled with a placeholder URL for local development. For production, see [Full app configuration](https://detour.swmansion.com/docs/Fundamentals/getting-started#4-complete-app-configuration).
38+
39+
[Dashboard › Apps](https://detour.swmansion.com/docs/Fundamentals/dashboard#apps)
40+
41+
42+
<div style="display: flex; gap: 10px; margin-bottom: 10px">
43+
<img src="assets/screenshots/dashboard-create-app-a.png" alt="Detour Dashboard organization creator" width="50%"/>
44+
<img src="assets/screenshots/dashboard-create-app-b.png" alt="Detour Dashboard app creator" width="50%"/>
45+
</div>
46+
<img src="assets/screenshots/dashboard-create-app-c.png" alt="Detour Dashboard app link details"/>
47+
<br>
48+
49+
> **Dashboard**. _Create an organization (top-left), create a new app (top-right), and use the generated link (marked with red) in Link settings (bottom)._
50+
51+
52+
### 2. Configure the platforms
53+
54+
Open **App configuration** and fill in the platform details:
55+
56+
- **iOS:** set Bundle ID to `detourreactnative.expobare` and provide Team ID and App Store ID. The **Team ID must be your real Apple Developer Team ID** — the one the build is signed with (`DEVELOPMENT_TEAM` in Xcode › Signing & Capabilities, also shown under [Apple Developer › Membership](https://developer.apple.com/account)). A placeholder or mismatched Team ID makes the Universal link open in Safari instead of the app. The App Store ID can stay a placeholder for local development.
57+
- **Android:** set package name to `detourreactnative.expobare` and add a SHA-256 certificate fingerprint. The **fingerprint must match the keystore that signs the build** — a wrong value makes Android open the App link in the browser instead of the app. For local development (`npx expo run:android`), use the **local debug keystore** fingerprint. See [Testing Android App Links](https://detour.swmansion.com/docs/sdk/react-native/testing#testing-android-app-links) for more info.
58+
59+
The dashboard generates the `associatedDomains` and intent-filter snippets to paste into `app.json` ([below](#configuring-appjson)).
60+
61+
> For a production integration, fill all fields with real values. See [App configuration](https://detour.swmansion.com/docs/Fundamentals/getting-started#app-configuration) for full guidance.
62+
63+
[Dashboard › App configuration](https://detour.swmansion.com/docs/Fundamentals/dashboard#app-configuration)
64+
65+
<img src="assets/screenshots/dashboard-app-configuration.png" alt="Detour Dashboard App configuration"/>
66+
<br>
67+
68+
> **Dashboard › App configuration**. _iOS and Android filled configurations with generated integration code snippets ready to copy._
2569
26-
1. Start the app on iOS/Android.
27-
2. Confirm the app renders and `isLinkProcessed` is `false`.
28-
3. Trigger a Detour link.
29-
4. Confirm `isLinkProcessed` flips to `true` and `type`, `url`, and `route` fields are populated on screen.
70+
### 3. Copy your credentials
71+
72+
Open **API configuration** and copy your `appID` and publishable `apiKey` into this example's `.env`.
73+
74+
[Dashboard › API configuration](https://detour.swmansion.com/docs/Fundamentals/dashboard#api-configuration-and-key-security)
75+
76+
<img src="assets/screenshots/dashboard-api-configuration.png" alt="Detour Dashboard API configuration"/>
77+
<br>
78+
79+
> **Dashboard › API configuration**. _The API configuration panel with `appID` and the publishable `apiKey` ready to copy._
3080
3181
## Configuring app.json
3282

33-
After registering your app in the [Detour Dashboard](https://godetour.dev), replace the placeholders in `app.json` with values from the **API configuration** section:
83+
Replace the placeholders in `app.json` with the values from the dashboard's [App configuration](https://detour.swmansion.com/docs/Fundamentals/dashboard#app-configuration) section:
3484

3585
- `<your-org>` — your organization slug
3686
- `<your-app-hash>` — the path prefix assigned to your app
3787

3888
```json
3989
"ios": {
40-
"bundleIdentifier": "<your-bundle-identifier",
90+
// ...
4191
"associatedDomains": ["applinks:<your-org>.godetour.link"]
4292
},
4393
"android": {
44-
"package": "<your-package>",
94+
// ...
4595
"intentFilters": [{
46-
"data": [{ "host": "<your-org>.godetour.link", "pathPrefix": "/<your-app-hash>" }]
96+
// ...
97+
"data": [{ "scheme": "https", "host": "<your-org>.godetour.link", "pathPrefix": "/<your-app-hash>" }]
4798
}]
4899
}
49100
```
50101

51-
These same values go into the simulator commands in the section below.
102+
> **Universal Links not opening the app?** Add `?mode=developer` to the `associatedDomains` entry: `"applinks:<your-org>.godetour.link?mode=developer"`. This bypasses Apple's CDN and fetches the AASA file directly from your domain on every launch instead of relying on a potentially stale cached version. Requires **Settings → Developer → Associated Domains Development** to be enabled on the device and a development-signed build. Remove it before submitting to TestFlight or the App Store.
103+
104+
These same values go into the simulator commands in the next section.
52105

53106
## Triggering links
54107

55-
**Universal / App link** — open a Detour HTTPS link:
108+
<details>
109+
<summary>Deferred deep link</summary>
110+
111+
Follow these steps to test the deferred flow:
112+
113+
1. Uninstall the app or clear its data to start from a clean state.
114+
2. Open a Detour link in the device's mobile browser.
115+
3. Install and launch the app — the SDK resolves the link automatically.
116+
117+
> **Note:** On Android, the install referrer is typically unavailable in development builds, so deferred matching falls back to probabilistic signals (IP, device fingerprint) only. See [Limitations & Known Issues](https://detour.swmansion.com/docs/Architecture/architecture-limitations).
118+
119+
Alternatively on iOS, you can also copy the link to your clipboard before uninstalling — the SDK reads the clipboard on first launch (`shouldUseClipboard: true`), so you can skip the browser step. It simulates a link clicked before the app was installed.
120+
121+
</details>
122+
123+
<details>
124+
<summary>Universal / App link</summary>
125+
126+
Open a Detour link directly from the terminal:
56127

57128
```sh
58129
# iOS simulator
@@ -62,17 +133,38 @@ xcrun simctl openurl booted "https://<your-org>.godetour.link/<your-app-hash>/"
62133
adb shell am start -a android.intent.action.VIEW -d "https://<your-org>.godetour.link/<your-app-hash>/"
63134
```
64135

65-
**Deferred link** — simulates a link clicked before the app was installed:
136+
Alternatively, paste the link into Notes or Messages on the device and tap it — this uses the same OS routing path a real user would.
66137

67-
1. Copy a Detour link URL from the Dashboard to your clipboard.
68-
2. Kill or uninstall the app.
69-
3. Relaunch — the SDK reads the clipboard on startup and resolves the link automatically.
138+
</details>
139+
140+
<details>
141+
<summary>Custom scheme</summary>
142+
143+
```sh
144+
# iOS simulator
145+
npx uri-scheme open "detour-expo-bare://details" --ios
146+
147+
# Android emulator
148+
npx uri-scheme open "detour-expo-bare://details" --android
149+
```
150+
151+
</details>
152+
153+
For more cases and gotchas, see [Testing & Troubleshooting](https://detour.swmansion.com/docs/sdk/react-native/testing).
70154

71155
## Quick start
72156

73157
- Install dependencies from the repo root: `pnpm install`
74-
- Configure this app in Detour Dashboard: `https://godetour.dev` using identifiers from `app.json` (for example `ios.bundleIdentifier`, `android.package`).
75-
- Use values from Dashboard from "API configuration" section to fill `.env` and update `app.json` with generated integration code.
158+
- Configure this app in the [Detour Dashboard](https://godetour.dev) using identifiers from `app.json` (for example `ios.bundleIdentifier`, `android.package`).
159+
- Use the values from the dashboard's [API configuration](https://detour.swmansion.com/docs/Fundamentals/dashboard#api-configuration-and-key-security) section to fill `.env` and update `app.json` with the generated integration code.
76160
- Run prebuild for this example: `pnpm prebuild`
77161
- Start the example: `pnpm start`
78162
- Run on device/simulator: `pnpm ios` or `pnpm android`
163+
164+
## See also
165+
166+
- [SDK Usage](https://detour.swmansion.com/docs/sdk/react-native/sdk-usage) — how to integrate Detour with your navigation library
167+
- [API Reference](https://detour.swmansion.com/docs/sdk/react-native/api-reference) — full type and method reference
168+
- [`examples/expo-router`](../expo-router) — minimal Expo Router integration
169+
- [`examples/expo-router-advanced`](../expo-router-advanced) — auth-gated Expo Router flow
170+
- [`examples/react-navigation`](../react-navigation) — minimal React Navigation integration
261 KB
Loading
124 KB
Loading
247 KB
Loading
82.9 KB
Loading
172 KB
Loading
249 KB
Loading

examples/expo-bare/src/Screen.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,16 @@ export const Screen = () => {
3939

4040
<View style={styles.divider} />
4141

42-
<Text style={styles.sectionHeader}>Universal / App Link</Text>
43-
<Text style={styles.bullet}>
44-
Open a Detour link in the browser — iOS/Android will launch the app. Test with the
45-
simulator using:
46-
</Text>
47-
<Text style={styles.code}>npx uri-scheme open {`"detour-expo-bare://"`} --ios</Text>
48-
4942
<Text style={styles.sectionHeader}>Deferred Link</Text>
5043
<Text style={styles.bullet}>
51-
Copy a Detour link to your clipboard, then kill and relaunch the app. Because{" "}
52-
<Text style={styles.accent}>shouldUseClipboard</Text> is enabled, Detour reads the
53-
clipboard on startup and resolves the pending link automatically.
44+
Uninstall the app or clear its data, open a Detour link in the mobile browser, then
45+
install and launch — the SDK resolves the link automatically.
5446
</Text>
47+
<Text style={styles.code}>https://&lt;your-org&gt;.godetour.link/&lt;hash&gt;/</Text>
48+
49+
<Text style={styles.sectionHeader}>Universal / App Link</Text>
5550
<Text style={styles.bullet}>
56-
Make sure <Text style={styles.accent}>Copy link feature enabled</Text> is turned on in
57-
App Configuration in the Detour panel.
51+
Open in browser or paste into Notes/Messages and tap — iOS/Android will launch the app.
5852
</Text>
5953
<Text style={styles.code}>https://&lt;your-org&gt;.godetour.link/&lt;hash&gt;/</Text>
6054

0 commit comments

Comments
 (0)