Skip to content

Commit 02c8321

Browse files
committed
refactor: move expo-router imports to dedicated path
1 parent 868d8a2 commit 02c8321

9 files changed

Lines changed: 46 additions & 48 deletions

File tree

examples/expo-router-advanced/app/+native-intent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
createDetourNativeIntentHandler,
3-
type NativeIntentArgs,
4-
} from '@swmansion/react-native-detour';
3+
type DetourNativeIntentArgs,
4+
} from '@swmansion/react-native-detour/expo-router';
55
import { applicationName } from 'expo-application';
66

77
// Example of a custom native intent handler that first delegates to Detour for processing,
@@ -10,7 +10,7 @@ const detourHandler = createDetourNativeIntentHandler({
1010
hosts: [/\.godetour\.link$/i],
1111
});
1212

13-
export async function redirectSystemPath(args: NativeIntentArgs) {
13+
export async function redirectSystemPath(args: DetourNativeIntentArgs) {
1414
// First let Detour process the incoming path to handle any matching deferred links.
1515
const detourResult = await detourHandler(args);
1616
if (detourResult !== args.path) {

examples/expo-router-native-intent/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Detour Expo Router Native Intent Example
22

3-
This example demonstrates the **new Expo Router native-intent API** from `@swmansion/react-native-detour`.
3+
This example demonstrates the **new Expo Router native-intent API** from `@swmansion/react-native-detour/expo-router`.
44

55
## What this example shows
66

77
Unlike the basic `examples/expo-router` setup, this app uses `createDetourNativeIntentHandler` in **resolve mode**:
88

99
- `app/+native-intent.tsx`
10-
- calls `createDetourNativeIntentHandler(...)` with `config` (`API_KEY`, `appID`, `timeoutMs`),
10+
- calls `createDetourNativeIntentHandler(...)` with `config` (`apiKey`, `appID`, `timeoutMs`),
1111
- resolves Detour short links inside native intent,
1212
- maps resolved URLs to Expo Router paths via `mapToRoute`.
1313
- `app/_layout.tsx`

examples/expo-router-native-intent/app/+native-intent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour';
1+
import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour/expo-router';
22

33
const detourNativeIntentHandler = createDetourNativeIntentHandler({
44
fallbackPath: '',

examples/expo-router/app/+native-intent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour';
1+
import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour/expo-router';
22

33
// Example of a custom native intent handler that delegates to Detour for processing.
44
// It detects links from Detour domain by default, but you can customize it further with the `hosts` option to fit your needs.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"types": "./lib/typescript/src/index.d.ts",
1111
"default": "./lib/module/index.js"
1212
},
13+
"./expo-router": {
14+
"source": "./src/expo-router/index.ts",
15+
"types": "./lib/typescript/src/expo-router/index.d.ts",
16+
"default": "./lib/module/expo-router/index.js"
17+
},
1318
"./package.json": "./package.json"
1419
},
1520
"files": [

src/expo-router/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export { createDetourNativeIntentHandler } from './nativeIntent';
2+
3+
export type {
4+
DetourNativeIntentArgs,
5+
DetourNativeIntentHandler,
6+
DetourNativeIntentOptions,
7+
DetourNativeIntentResolveConfig,
8+
DetourNativeIntentResolvedValue,
9+
} from './nativeIntent';

src/expo-router/nativeIntent.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getRouteFromDeepLink } from '../links/utils/urlHelpers';
55
/**
66
* Arguments passed by Expo Router to `redirectSystemPath`.
77
*/
8-
export type NativeIntentArgs = {
8+
export type DetourNativeIntentArgs = {
99
/**
1010
* Incoming system path/URL that should be evaluated.
1111
*/
@@ -19,21 +19,14 @@ export type NativeIntentArgs = {
1919
/**
2020
* Function signature compatible with Expo Router native intent handlers.
2121
*/
22-
export type NativeIntentHandler = (
23-
args: NativeIntentArgs
22+
export type DetourNativeIntentHandler = (
23+
args: DetourNativeIntentArgs
2424
) => string | Promise<string>;
2525

26-
/**
27-
* Match context with a parsed URL object.
28-
*/
29-
export type NativeIntentMatchContext = NativeIntentArgs & {
30-
url: URL;
31-
};
32-
3326
/**
3427
* Value passed to `mapToRoute` after URL resolution.
3528
*/
36-
export type NativeIntentResolvedValue = {
29+
export type DetourNativeIntentResolvedValue = {
3730
/**
3831
* Original incoming system path passed by Expo Router.
3932
*/
@@ -51,7 +44,10 @@ export type NativeIntentResolvedValue = {
5144
/**
5245
* Resolve configuration for `createDetourNativeIntentHandler`.
5346
*/
54-
export type NativeIntentResolveConfig = Pick<Config, 'apiKey' | 'appID'> & {
47+
export type DetourNativeIntentResolveConfig = Pick<
48+
Config,
49+
'apiKey' | 'appID'
50+
> & {
5551
/**
5652
* Timeout for short-link resolution call.
5753
* Defaults to `1200` ms.
@@ -60,7 +56,7 @@ export type NativeIntentResolveConfig = Pick<Config, 'apiKey' | 'appID'> & {
6056
/**
6157
* Optional callback invoked when short-link resolution fails or times out.
6258
*/
63-
onResolveError?: (error: unknown, context: NativeIntentArgs) => void;
59+
onResolveError?: (error: unknown, context: DetourNativeIntentArgs) => void;
6460
};
6561

6662
/**
@@ -93,19 +89,14 @@ export type DetourNativeIntentOptions = {
9389
* Without this field, the handler works in intercept mode and simply returns
9490
* `fallbackPath` on host match.
9591
*/
96-
config?: NativeIntentResolveConfig;
92+
config?: DetourNativeIntentResolveConfig;
9793
/**
9894
* Optional mapping callback used in resolve mode.
9995
* If omitted, SDK uses the default mapping strategy.
10096
*/
101-
mapToRoute?: (value: NativeIntentResolvedValue) => string;
97+
mapToRoute?: (value: DetourNativeIntentResolvedValue) => string;
10298
};
10399

104-
/**
105-
* Backward-compatible alias for options type.
106-
*/
107-
export type NativeIntentOptions = DetourNativeIntentOptions;
108-
109100
const DEFAULT_HOSTS: Array<string | RegExp> = [/\.godetour\.link$/i];
110101
const DEFAULT_TIMEOUT_MS = 1200;
111102

@@ -186,7 +177,9 @@ const normalizeRoute = (value: string, fallbackPath: string) => {
186177
* Custom scheme mapping:
187178
* - convert to Expo Router path (`myapp://app/details?id=1` -> `/app/details?id=1`)
188179
*/
189-
const defaultMapToRoute = ({ resolvedUrl }: NativeIntentResolvedValue) => {
180+
const defaultMapToRoute = ({
181+
resolvedUrl,
182+
}: DetourNativeIntentResolvedValue) => {
190183
if (!isWebProtocol(resolvedUrl)) {
191184
return getRouteFromDeepLink(resolvedUrl);
192185
}
@@ -249,7 +242,7 @@ const withTimeout = async <T>(promise: Promise<T>, timeoutMs: number) => {
249242
* @returns A `redirectSystemPath` handler function compatible with Expo Router.
250243
* @example
251244
* ```tsx title="app/+native-intent.tsx"
252-
* import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour';
245+
* import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour/expo-router';
253246
*
254247
* export const redirectSystemPath = createDetourNativeIntentHandler({
255248
* fallbackPath: '',
@@ -258,7 +251,7 @@ const withTimeout = async <T>(promise: Promise<T>, timeoutMs: number) => {
258251
*
259252
* @example
260253
* ```tsx title="app/+native-intent.tsx"
261-
* import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour';
254+
* import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour/expo-router';
262255
*
263256
* export const redirectSystemPath = createDetourNativeIntentHandler({
264257
* fallbackPath: '',
@@ -268,12 +261,12 @@ const withTimeout = async <T>(promise: Promise<T>, timeoutMs: number) => {
268261
*
269262
* @example
270263
* ```tsx title="app/+native-intent.tsx"
271-
* import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour';
264+
* import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour/expo-router';
272265
*
273266
* export const redirectSystemPath = createDetourNativeIntentHandler({
274267
* fallbackPath: '',
275268
* config: {
276-
* API_KEY: process.env.EXPO_PUBLIC_DETOUR_API_KEY!,
269+
* apiKey: process.env.EXPO_PUBLIC_DETOUR_API_KEY!,
277270
* appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID!,
278271
* timeoutMs: 1200,
279272
* },
@@ -285,12 +278,12 @@ const withTimeout = async <T>(promise: Promise<T>, timeoutMs: number) => {
285278
*/
286279
export const createDetourNativeIntentHandler = (
287280
options: DetourNativeIntentOptions = {}
288-
): NativeIntentHandler => {
281+
): DetourNativeIntentHandler => {
289282
const fallbackPath = options.fallbackPath ?? '';
290283
const hosts = options.hosts?.length ? options.hosts : DEFAULT_HOSTS;
291284
const mapToRoute = options.mapToRoute ?? defaultMapToRoute;
292285

293-
return async ({ path, initial }: NativeIntentArgs) => {
286+
return async ({ path, initial }: DetourNativeIntentArgs) => {
294287
const url = parseIntentUrl(path);
295288
if (!url?.hostname) {
296289
return path;

src/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ export type {
55
DetourContextType,
66
DetourStorage,
77
} from './links/types/index';
8-
export type { ResolveShortLinkResponse } from './links/api/resolveShortLink';
98

109
export { DetourAnalytics } from './analytics/analytics';
11-
export type { DetourEventNames } from './analytics/types/index';
12-
13-
export { createDetourNativeIntentHandler } from './expo-router/nativeIntent';
14-
export type {
15-
DetourNativeIntentOptions,
16-
NativeIntentArgs,
17-
NativeIntentHandler,
18-
NativeIntentMatchContext,
19-
NativeIntentOptions,
20-
NativeIntentResolveConfig,
21-
NativeIntentResolvedValue,
22-
} from './expo-router/nativeIntent';
10+
export { DetourEventNames } from './analytics/types/index';

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"compilerOptions": {
33
"rootDir": ".",
44
"paths": {
5-
"@swmansion/react-native-detour": ["./src/index"]
5+
"@swmansion/react-native-detour": ["./src/index"],
6+
"@swmansion/react-native-detour/expo-router": [
7+
"./src/expo-router/index"
8+
]
69
},
710
"allowUnreachableCode": false,
811
"allowUnusedLabels": false,

0 commit comments

Comments
 (0)