@rn-tools/navigation 2.2.1 → 2.2.2
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 +6 -7
- package/package.json +1 -1
- package/src/deep-links.tsx +4 -8
package/README.md
CHANGED
|
@@ -530,13 +530,12 @@ let useUser = () => {
|
|
|
530
530
|
|
|
531
531
|
### Deep Links
|
|
532
532
|
|
|
533
|
-
This section will cover how to respond to deep links in your app. Deep links usually have some extra setup required - use Expo's [Deep Linking Guide](https://docs.expo.dev/guides/deep-linking/) to get started.
|
|
533
|
+
This section will cover how to respond to deep links in your app. Deep links usually have some extra setup required - use Expo's [Deep Linking Guide](https://docs.expo.dev/guides/deep-linking/) to get started. Once you are able to receive deep links, use the `DeepLinks` component exported from this library to handle them.
|
|
534
534
|
|
|
535
|
-
|
|
535
|
+
In this example we will have a basic 3 tab view. We want to repond to the link `home/items/:id` by navigating to the home tab and then pushing a detail screen with the corresponding item id. The deep link component takes an array of handlers which are functions that will be invoked when their `path` matches the deep link that was opened.
|
|
536
536
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
- 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.
|
|
537
|
+
- Only the first matching handler will be invoked.
|
|
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.
|
|
540
539
|
|
|
541
540
|
```tsx
|
|
542
541
|
import { DeepLinks, navigation, Stack, Tabs } from "@rn-tools/navigation";
|
|
@@ -550,14 +549,14 @@ export function DeepLinksExample() {
|
|
|
550
549
|
// let { path } = Linking.parse(url)
|
|
551
550
|
|
|
552
551
|
// But it's easier to test hardcoded strings for the sake of this example
|
|
553
|
-
let path = "/
|
|
552
|
+
let path = "/home/item/4";
|
|
554
553
|
|
|
555
554
|
return (
|
|
556
555
|
<DeepLinks
|
|
557
556
|
path={path}
|
|
558
557
|
handlers={[
|
|
559
558
|
{
|
|
560
|
-
path: "/
|
|
559
|
+
path: "/home/item/:itemId",
|
|
561
560
|
handler: (params: { itemId: string }) => {
|
|
562
561
|
let itemId = params.itemId;
|
|
563
562
|
|
package/package.json
CHANGED
package/src/deep-links.tsx
CHANGED
|
@@ -20,14 +20,10 @@ type DeepLinksProps<T> = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export function DeepLinks<T>({ path, handlers, children }: DeepLinksProps<T>) {
|
|
23
|
-
let matchers = React.useRef(buildMatchers(handlers));
|
|
24
|
-
|
|
25
|
-
React.useLayoutEffect(() => {
|
|
26
|
-
matchers.current = buildMatchers(handlers);
|
|
27
|
-
}, [handlers]);
|
|
28
|
-
|
|
29
23
|
React.useEffect(() => {
|
|
30
|
-
|
|
24
|
+
let matchers = buildMatchers(handlers);
|
|
25
|
+
|
|
26
|
+
for (let matcher of matchers) {
|
|
31
27
|
let { fn, handler } = matcher;
|
|
32
28
|
let match = fn(path);
|
|
33
29
|
if (match) {
|
|
@@ -35,7 +31,7 @@ export function DeepLinks<T>({ path, handlers, children }: DeepLinksProps<T>) {
|
|
|
35
31
|
break;
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
|
-
}, [path]);
|
|
34
|
+
}, [path, handlers]);
|
|
39
35
|
|
|
40
36
|
return <>{children}</>;
|
|
41
37
|
}
|