@rn-tools/navigation 2.2.2 → 2.2.4

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,45 +536,66 @@ 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
- export function DeepLinksExample() {
547
+ export default function DeepLinksExample() {
547
548
  // You'll likely want to use Expo's Linking API to get the current URL and path
548
549
  // let url = Linking.useURL()
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/2";
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
 
@@ -644,7 +665,14 @@ function MyScreen({
644
665
  }) {
645
666
  return (
646
667
  <View style={{ flex: 1, backgroundColor: bg }}>
647
- <View className="flex-1 items-center justify-center gap-4">
668
+ <View
669
+ style={{
670
+ flex: 1,
671
+ justifyContent: "center",
672
+ alignItems: "center",
673
+ gap: 4,
674
+ }}
675
+ >
648
676
  <Text style={{ fontSize: 26, fontWeight: "semibold" }}>{title}</Text>
649
677
 
650
678
  {!isRoot && (
@@ -660,6 +688,7 @@ function MyScreen({
660
688
  </View>
661
689
  );
662
690
  }
691
+
663
692
  ```
664
693
 
665
694
  ### 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.4",
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
 
package/src/utils.ts CHANGED
@@ -34,7 +34,7 @@ export function useSafeAreaInsetsSafe() {
34
34
  // eslint-disable-next-line
35
35
  insets = useSafeAreaInsets();
36
36
  } catch (error) {
37
- console.log("useSafeAreaInsets is not available");
37
+ console.warn("`react-native-safe-area-context` missing - Please install and wrap your app in a SafeAreaProvider" );
38
38
  }
39
39
 
40
40
  return insets;