@rn-tools/navigation 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -25
- package/package.json +1 -1
- package/src/deep-links.tsx +1 -1
package/README.md
CHANGED
|
@@ -536,12 +536,13 @@ In this example we will have a basic 3 tab view. We want to repond to the link `
|
|
|
536
536
|
|
|
537
537
|
- Only the first matching handler will be invoked.
|
|
538
538
|
- The handler function will receive the params from the deep link - these use the same token syntax as libraries like `react-router` and `express` for path params.
|
|
539
|
+
- Make sure that the `DeepLinks` component is inside of a `Stack` component
|
|
539
540
|
|
|
540
541
|
```tsx
|
|
541
542
|
import { DeepLinks, navigation, Stack, Tabs } from "@rn-tools/navigation";
|
|
543
|
+
import * as Linking from "expo-linking";
|
|
542
544
|
import * as React from "react";
|
|
543
545
|
import { View, Text, TouchableOpacity } from "react-native";
|
|
544
|
-
import * as Linking from "expo-linking";
|
|
545
546
|
|
|
546
547
|
export function DeepLinksExample() {
|
|
547
548
|
// You'll likely want to use Expo's Linking API to get the current URL and path
|
|
@@ -549,32 +550,52 @@ export function DeepLinksExample() {
|
|
|
549
550
|
// let { path } = Linking.parse(url)
|
|
550
551
|
|
|
551
552
|
// But it's easier to test hardcoded strings for the sake of this example
|
|
552
|
-
let path = "/home/item/
|
|
553
|
+
let path = "/testing/home/item/1";
|
|
553
554
|
|
|
554
555
|
return (
|
|
555
|
-
<
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
556
|
+
<Stack.Navigator
|
|
557
|
+
rootScreen={
|
|
558
|
+
<DeepLinks
|
|
559
|
+
path={path}
|
|
560
|
+
handlers={[
|
|
561
|
+
{
|
|
562
|
+
path: "/testing/home/item1/:itemId",
|
|
563
|
+
handler: (params: { itemId: string }) => {
|
|
564
|
+
let itemId = params.itemId;
|
|
565
|
+
|
|
566
|
+
// Go to home tab
|
|
567
|
+
navigation.setTabIndex(0);
|
|
568
|
+
|
|
569
|
+
// Push the screen we want
|
|
570
|
+
navigation.pushScreen(
|
|
571
|
+
<Stack.Screen>
|
|
572
|
+
<MyScreen title={`Item: ${itemId}`} />
|
|
573
|
+
</Stack.Screen>
|
|
574
|
+
);
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
path: "/testing/home/item/:itemId",
|
|
579
|
+
handler: (params: { itemId: string }) => {
|
|
580
|
+
let itemId = params.itemId;
|
|
581
|
+
|
|
582
|
+
// Go to home tab
|
|
583
|
+
navigation.setTabIndex(0);
|
|
584
|
+
|
|
585
|
+
// Push the screen we want
|
|
586
|
+
navigation.pushScreen(
|
|
587
|
+
<Stack.Screen>
|
|
588
|
+
<MyScreen title={`Item: ${itemId}`} />
|
|
589
|
+
</Stack.Screen>
|
|
590
|
+
);
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
]}
|
|
594
|
+
>
|
|
595
|
+
<MyTabs />
|
|
596
|
+
</DeepLinks>
|
|
597
|
+
}
|
|
598
|
+
/>
|
|
578
599
|
);
|
|
579
600
|
}
|
|
580
601
|
|
|
@@ -660,6 +681,7 @@ function MyScreen({
|
|
|
660
681
|
</View>
|
|
661
682
|
);
|
|
662
683
|
}
|
|
684
|
+
|
|
663
685
|
```
|
|
664
686
|
|
|
665
687
|
### Preventing going back
|
package/package.json
CHANGED
package/src/deep-links.tsx
CHANGED
|
@@ -19,7 +19,7 @@ type DeepLinksProps<T> = {
|
|
|
19
19
|
children: React.ReactNode;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export function DeepLinks<T>({ path, handlers, children }: DeepLinksProps<T>) {
|
|
22
|
+
export function DeepLinks<T>({ path = '', handlers = [], children }: DeepLinksProps<T>) {
|
|
23
23
|
React.useEffect(() => {
|
|
24
24
|
let matchers = buildMatchers(handlers);
|
|
25
25
|
|