@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 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/4";
553
+ let path = "/testing/home/item/1";
553
554
 
554
555
  return (
555
- <DeepLinks
556
- path={path}
557
- handlers={[
558
- {
559
- path: "/home/item/:itemId",
560
- handler: (params: { itemId: string }) => {
561
- let itemId = params.itemId;
562
-
563
- // Go to home tab
564
- navigation.setTabIndex(0);
565
-
566
- // Push the screen we want
567
- navigation.pushScreen(
568
- <Stack.Screen>
569
- <MyScreen title={`Item: ${itemId}`} />
570
- </Stack.Screen>
571
- );
572
- },
573
- },
574
- ]}
575
- >
576
- <MyTabs />
577
- </DeepLinks>
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rn-tools/navigation",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "main": "./src/index.ts",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -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