@react-navigation/native 6.0.4 → 6.0.8

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.
Files changed (39) hide show
  1. package/lib/commonjs/Link.js +6 -5
  2. package/lib/commonjs/Link.js.map +1 -1
  3. package/lib/commonjs/NavigationContainer.js +9 -8
  4. package/lib/commonjs/NavigationContainer.js.map +1 -1
  5. package/lib/commonjs/ServerContainer.js +5 -4
  6. package/lib/commonjs/ServerContainer.js.map +1 -1
  7. package/lib/commonjs/ServerContext.js.map +1 -1
  8. package/lib/commonjs/index.js +16 -16
  9. package/lib/commonjs/theming/ThemeProvider.js +5 -4
  10. package/lib/commonjs/theming/ThemeProvider.js.map +1 -1
  11. package/lib/commonjs/useDocumentTitle.js +9 -8
  12. package/lib/commonjs/useDocumentTitle.js.map +1 -1
  13. package/lib/commonjs/useLinkProps.js +8 -7
  14. package/lib/commonjs/useLinkProps.js.map +1 -1
  15. package/lib/commonjs/useLinking.js +61 -40
  16. package/lib/commonjs/useLinking.js.map +1 -1
  17. package/lib/commonjs/useLinking.native.js +34 -29
  18. package/lib/commonjs/useLinking.native.js.map +1 -1
  19. package/lib/module/Link.js +6 -5
  20. package/lib/module/Link.js.map +1 -1
  21. package/lib/module/NavigationContainer.js +9 -8
  22. package/lib/module/NavigationContainer.js.map +1 -1
  23. package/lib/module/ServerContainer.js +5 -4
  24. package/lib/module/ServerContainer.js.map +1 -1
  25. package/lib/module/ServerContext.js.map +1 -1
  26. package/lib/module/theming/ThemeProvider.js +5 -4
  27. package/lib/module/theming/ThemeProvider.js.map +1 -1
  28. package/lib/module/useDocumentTitle.js +8 -7
  29. package/lib/module/useDocumentTitle.js.map +1 -1
  30. package/lib/module/useLinkProps.js +8 -7
  31. package/lib/module/useLinkProps.js.map +1 -1
  32. package/lib/module/useLinking.js +58 -38
  33. package/lib/module/useLinking.js.map +1 -1
  34. package/lib/module/useLinking.native.js +33 -28
  35. package/lib/module/useLinking.native.js.map +1 -1
  36. package/package.json +7 -6
  37. package/src/ServerContext.tsx +3 -2
  38. package/src/useLinking.native.tsx +6 -1
  39. package/src/useLinking.tsx +47 -15
@@ -1 +1 @@
1
- {"version":3,"sources":["useLinkProps.tsx"],"names":["getPathFromState","NavigationContainerRefContext","NavigationHelpersContext","React","Platform","LinkingContext","useLinkTo","getStateFromParams","params","state","screen","routes","name","undefined","useLinkProps","to","action","root","useContext","navigation","options","linkTo","onPress","e","shouldHandle","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","includes","currentTarget","target","preventDefault","dispatch","Error","getPathFromStateHelper","href","config","accessibilityRole"],"mappings":"AAAA,SACEA,gBADF,EAGEC,6BAHF,EAIEC,wBAJF,QAOO,wBAPP;AASA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAAgCC,QAAhC,QAAgD,cAAhD;AAEA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,SAAP,MAA8B,aAA9B;;AAOA,MAAMC,kBAAkB,GACtBC,MADyB,IAEuC;AAChE,MAAIA,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEC,KAAZ,EAAmB;AACjB,WAAOD,MAAM,CAACC,KAAd;AACD;;AAED,MAAID,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEE,MAAZ,EAAoB;AAClB,WAAO;AACLC,MAAAA,MAAM,EAAE,CACN;AACEC,QAAAA,IAAI,EAAEJ,MAAM,CAACE,MADf;AAEEF,QAAAA,MAAM,EAAEA,MAAM,CAACA,MAFjB;AAGE;AACAC,QAAAA,KAAK,EAAED,MAAM,CAACE,MAAP,GACHH,kBAAkB,CAChBC,MAAM,CAACA,MADS,CADf,GAMHK;AAVN,OADM;AADH,KAAP;AAgBD;;AAED,SAAOA,SAAP;AACD,CA3BD;AA6BA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,YAAT,CAEb;AAAEC,EAAAA,EAAF;AAAMC,EAAAA;AAAN,CAFa,EAEqB;A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ACD,SAFM,MAEA;AACL,gBAAM,IAAIqB,KAAJ,CACJ,kFADI,CAAN;AAGD;AACF,OAVD,MAUO;AACLhB,QAAAA,MAAM,CAACN,EAAD,CAAN;AACD;AACF;AACF,GAnCD;;AAqCA,QAAMuB,sBAAsB,4BAAGlB,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEpB,gBAAZ,yEAAgCA,gBAA5D;AAEA,QAAMuC,IAAI,GACR,OAAOxB,EAAP,KAAc,QAAd,GACIA,EADJ,GAEIuB,sBAAsB,CACpB;AACE3B,IAAAA,MAAM,EAAE,CACN;AACEC,MAAAA,IAAI,EAAEG,EAAE,CAACL,MADX;AAEE;AACAF,MAAAA,MAAM,EAAEO,EAAE,CAACP,MAHb;AAIE;AACAC,MAAAA,KAAK,EAAEF,kBAAkB,CAACQ,EAAE,CAACP,MAAJ;AAL3B,KADM;AADV,GADoB,EAYpBY,OAZoB,aAYpBA,OAZoB,uBAYpBA,OAAO,CAAEoB,MAZW,CAH5B;AAkBA,SAAO;AACLD,IAAAA,IADK;AAELE,IAAAA,iBAAiB,EAAE,MAFd;AAGLnB,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import {\n getPathFromState,\n NavigationAction,\n NavigationContainerRefContext,\n NavigationHelpersContext,\n NavigatorScreenParams,\n ParamListBase,\n} from '@react-navigation/core';\nimport type { NavigationState, PartialState } from '@react-navigation/routers';\nimport * as React from 'react';\nimport { GestureResponderEvent, Platform } from 'react-native';\n\nimport LinkingContext from './LinkingContext';\nimport useLinkTo, { To } from './useLinkTo';\n\ntype Props<ParamList extends ReactNavigation.RootParamList> = {\n to: To<ParamList>;\n action?: NavigationAction;\n};\n\nconst getStateFromParams = (\n params: NavigatorScreenParams<ParamListBase, NavigationState> | undefined\n): PartialState<NavigationState> | NavigationState | undefined => {\n if (params?.state) {\n return params.state;\n }\n\n if (params?.screen) {\n return {\n routes: [\n {\n name: params.screen,\n params: params.params,\n // @ts-expect-error\n state: params.screen\n ? getStateFromParams(\n params.params as\n | NavigatorScreenParams<ParamListBase, NavigationState>\n | undefined\n )\n : undefined,\n },\n ],\n };\n }\n\n return undefined;\n};\n\n/**\n * Hook to get props for an anchor tag so it can work with in page navigation.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n */\nexport default function useLinkProps<\n ParamList extends ReactNavigation.RootParamList\n>({ to, action }: Props<ParamList>) {\n const root = React.useContext(NavigationContainerRefContext);\n const navigation = React.useContext(NavigationHelpersContext);\n const { options } = React.useContext(LinkingContext);\n const linkTo = useLinkTo<ParamList>();\n\n const onPress = (\n e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n let shouldHandle = false;\n\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (\n !e.defaultPrevented && // onPress prevented default\n // @ts-expect-error: these properties exist on web, but not in React Native\n !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys\n // @ts-expect-error: these properties exist on web, but not in React Native\n (e.button == null || e.button === 0) && // ignore everything but left clicks\n // @ts-expect-error: these properties exist on web, but not in React Native\n [undefined, null, '', 'self'].includes(e.currentTarget?.target) // let browser handle \"target=_blank\" etc.\n ) {\n e.preventDefault();\n shouldHandle = true;\n }\n\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else if (root) {\n root.dispatch(action);\n } else {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n } else {\n linkTo(to);\n }\n }\n };\n\n const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;\n\n const href =\n typeof to === 'string'\n ? to\n : getPathFromStateHelper(\n {\n routes: [\n {\n name: to.screen,\n // @ts-expect-error\n params: to.params,\n // @ts-expect-error\n state: getStateFromParams(to.params),\n },\n ],\n },\n options?.config\n );\n\n return {\n href,\n accessibilityRole: 'link' as const,\n onPress,\n };\n}\n"]}
1
+ {"version":3,"sources":["useLinkProps.tsx"],"names":["getPathFromState","NavigationContainerRefContext","NavigationHelpersContext","React","Platform","LinkingContext","useLinkTo","getStateFromParams","params","state","screen","routes","name","undefined","useLinkProps","to","action","root","useContext","navigation","options","linkTo","onPress","e","shouldHandle","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","includes","currentTarget","target","preventDefault","dispatch","Error","getPathFromStateHelper","href","config","accessibilityRole"],"mappings":"AAAA,SACEA,gBADF,EAGEC,6BAHF,EAIEC,wBAJF,QAOO,wBAPP;AASA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAAgCC,QAAhC,QAAgD,cAAhD;AAEA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,SAAP,MAA8B,aAA9B;;AAOA,MAAMC,kBAAkB,GACtBC,MADyB,IAEuC;AAChE,MAAIA,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEC,KAAZ,EAAmB;AACjB,WAAOD,MAAM,CAACC,KAAd;AACD;;AAED,MAAID,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEE,MAAZ,EAAoB;AAClB,WAAO;AACLC,MAAAA,MAAM,EAAE,CACN;AACEC,QAAAA,IAAI,EAAEJ,MAAM,CAACE,MADf;AAEEF,QAAAA,MAAM,EAAEA,MAAM,CAACA,MAFjB;AAGE;AACAC,QAAAA,KAAK,EAAED,MAAM,CAACE,MAAP,GACHH,kBAAkB,CAChBC,MAAM,CAACA,MADS,CADf,GAMHK;AAVN,OADM;AADH,KAAP;AAgBD;;AAED,SAAOA,SAAP;AACD,CA3BD;AA6BA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,YAAT,OAEqB;AAAA;;AAAA,MAAlC;AAAEC,IAAAA,EAAF;AAAMC,IAAAA;AAAN,GAAkC;AAClC,QAAMC,IAAI,GAAGd,KAAK,CAACe,UAAN,CAAiBjB,6BAAjB,CAAb;AACA,QAAMkB,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hB,QAAAA,MAAM,CAACN,EAAD,CAAN;AACD;AACF;AACF,GAnCD;;AAqCA,QAAMuB,sBAAsB,4BAAGlB,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEpB,gBAAZ,yEAAgCA,gBAA5D;AAEA,QAAMuC,IAAI,GACR,OAAOxB,EAAP,KAAc,QAAd,GACIA,EADJ,GAEIuB,sBAAsB,CACpB;AACE3B,IAAAA,MAAM,EAAE,CACN;AACEC,MAAAA,IAAI,EAAEG,EAAE,CAACL,MADX;AAEE;AACAF,MAAAA,MAAM,EAAEO,EAAE,CAACP,MAHb;AAIE;AACAC,MAAAA,KAAK,EAAEF,kBAAkB,CAACQ,EAAE,CAACP,MAAJ;AAL3B,KADM;AADV,GADoB,EAYpBY,OAZoB,aAYpBA,OAZoB,uBAYpBA,OAAO,CAAEoB,MAZW,CAH5B;AAkBA,SAAO;AACLD,IAAAA,IADK;AAELE,IAAAA,iBAAiB,EAAE,MAFd;AAGLnB,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import {\n getPathFromState,\n NavigationAction,\n NavigationContainerRefContext,\n NavigationHelpersContext,\n NavigatorScreenParams,\n ParamListBase,\n} from '@react-navigation/core';\nimport type { NavigationState, PartialState } from '@react-navigation/routers';\nimport * as React from 'react';\nimport { GestureResponderEvent, Platform } from 'react-native';\n\nimport LinkingContext from './LinkingContext';\nimport useLinkTo, { To } from './useLinkTo';\n\ntype Props<ParamList extends ReactNavigation.RootParamList> = {\n to: To<ParamList>;\n action?: NavigationAction;\n};\n\nconst getStateFromParams = (\n params: NavigatorScreenParams<ParamListBase, NavigationState> | undefined\n): PartialState<NavigationState> | NavigationState | undefined => {\n if (params?.state) {\n return params.state;\n }\n\n if (params?.screen) {\n return {\n routes: [\n {\n name: params.screen,\n params: params.params,\n // @ts-expect-error\n state: params.screen\n ? getStateFromParams(\n params.params as\n | NavigatorScreenParams<ParamListBase, NavigationState>\n | undefined\n )\n : undefined,\n },\n ],\n };\n }\n\n return undefined;\n};\n\n/**\n * Hook to get props for an anchor tag so it can work with in page navigation.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n */\nexport default function useLinkProps<\n ParamList extends ReactNavigation.RootParamList\n>({ to, action }: Props<ParamList>) {\n const root = React.useContext(NavigationContainerRefContext);\n const navigation = React.useContext(NavigationHelpersContext);\n const { options } = React.useContext(LinkingContext);\n const linkTo = useLinkTo<ParamList>();\n\n const onPress = (\n e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n let shouldHandle = false;\n\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (\n !e.defaultPrevented && // onPress prevented default\n // @ts-expect-error: these properties exist on web, but not in React Native\n !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys\n // @ts-expect-error: these properties exist on web, but not in React Native\n (e.button == null || e.button === 0) && // ignore everything but left clicks\n // @ts-expect-error: these properties exist on web, but not in React Native\n [undefined, null, '', 'self'].includes(e.currentTarget?.target) // let browser handle \"target=_blank\" etc.\n ) {\n e.preventDefault();\n shouldHandle = true;\n }\n\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else if (root) {\n root.dispatch(action);\n } else {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n } else {\n linkTo(to);\n }\n }\n };\n\n const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;\n\n const href =\n typeof to === 'string'\n ? to\n : getPathFromStateHelper(\n {\n routes: [\n {\n name: to.screen,\n // @ts-expect-error\n params: to.params,\n // @ts-expect-error\n state: getStateFromParams(to.params),\n },\n ],\n },\n options?.config\n );\n\n return {\n href,\n accessibilityRole: 'link' as const,\n onPress,\n };\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { findFocusedRoute, getActionFromState as getActionFromStateDefault, getPathFromState as getPathFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@react-navigation/core';
2
+ import isEqual from 'fast-deep-equal';
2
3
  import { nanoid } from 'nanoid/non-secure';
3
4
  import * as React from 'react';
4
5
  import ServerContext from './ServerContext';
@@ -41,9 +42,11 @@ const createMemoryHistory = () => {
41
42
  return items[index];
42
43
  },
43
44
 
44
- backIndex({
45
- path
46
- }) {
45
+ backIndex(_ref) {
46
+ let {
47
+ path
48
+ } = _ref;
49
+
47
50
  // We need to find the index from the element before current to get closest path to go back to
48
51
  for (let i = index - 1; i >= 0; i--) {
49
52
  const item = items[i];
@@ -56,10 +59,11 @@ const createMemoryHistory = () => {
56
59
  return -1;
57
60
  },
58
61
 
59
- push({
60
- path,
61
- state
62
- }) {
62
+ push(_ref2) {
63
+ let {
64
+ path,
65
+ state
66
+ } = _ref2;
63
67
  interrupt();
64
68
  const id = nanoid(); // When a new entry is pushed, all the existing entries after index will be inaccessible
65
69
  // So we remove any existing entries after the current index to clean them up
@@ -80,12 +84,13 @@ const createMemoryHistory = () => {
80
84
  }, '', path);
81
85
  },
82
86
 
83
- replace({
84
- path,
85
- state
86
- }) {
87
+ replace(_ref3) {
87
88
  var _window$history$state2, _window$history$state3;
88
89
 
90
+ let {
91
+ path,
92
+ state
93
+ } = _ref3;
89
94
  interrupt();
90
95
  const id = (_window$history$state2 = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id) !== null && _window$history$state2 !== void 0 ? _window$history$state2 : nanoid();
91
96
 
@@ -101,6 +106,7 @@ const createMemoryHistory = () => {
101
106
  state,
102
107
  id
103
108
  }];
109
+ index = 0;
104
110
  } else {
105
111
  items[index] = {
106
112
  path,
@@ -122,20 +128,13 @@ const createMemoryHistory = () => {
122
128
  go(n) {
123
129
  interrupt();
124
130
 
125
- if (n > 0) {
126
- // We shouldn't go forward more than available index
127
- n = Math.min(n, items.length - 1);
128
- } else if (n < 0) {
129
- // We shouldn't go back more than the 0 index
130
- // Otherwise we'll exit the page
131
- n = index + n < 0 ? -index : n;
132
- }
133
-
134
131
  if (n === 0) {
135
132
  return;
136
- }
133
+ } // We shouldn't go back more than the 0 index (otherwise we'll exit the page)
134
+ // Or forward more than the available index (or the app will crash)
137
135
 
138
- index += n; // When we call `history.go`, `popstate` will fire when there's history to go back to
136
+
137
+ index = n < 0 ? Math.max(index - n, 0) : Math.min(index + n, items.length - 1); // When we call `history.go`, `popstate` will fire when there's history to go back to
139
138
  // So we need to somehow handle following cases:
140
139
  // - There's history to go back, `history.go` is called, and `popstate` fires
141
140
  // - `history.go` is called multiple times, we need to resolve on respective `popstate`
@@ -287,14 +286,15 @@ const series = cb => {
287
286
  };
288
287
 
289
288
  let linkingHandlers = [];
290
- export default function useLinking(ref, {
291
- independent,
292
- enabled = true,
293
- config,
294
- getStateFromPath = getStateFromPathDefault,
295
- getPathFromState = getPathFromStateDefault,
296
- getActionFromState = getActionFromStateDefault
297
- }) {
289
+ export default function useLinking(ref, _ref4) {
290
+ let {
291
+ independent,
292
+ enabled = true,
293
+ config,
294
+ getStateFromPath = getStateFromPathDefault,
295
+ getPathFromState = getPathFromStateDefault,
296
+ getActionFromState = getActionFromStateDefault
297
+ } = _ref4;
298
298
  React.useEffect(() => {
299
299
  if (process.env.NODE_ENV === 'production') {
300
300
  return undefined;
@@ -416,7 +416,8 @@ export default function useLinking(ref, {
416
416
  } catch (e) {
417
417
  // Ignore any errors from deep linking.
418
418
  // This could happen in case of malformed links, navigation object not being initialized etc.
419
- console.warn(`An error occurred when trying to handle the link '${path}': ${e.message}`);
419
+ console.warn(`An error occurred when trying to handle the link '${path}': ${typeof e === 'object' && e != null && 'message' in e ? // @ts-expect-error: we're already checking for this
420
+ e.message : e}`);
420
421
  }
421
422
  } else {
422
423
  navigation.resetRoot(state);
@@ -437,16 +438,32 @@ export default function useLinking(ref, {
437
438
  return;
438
439
  }
439
440
 
441
+ const getPathForRoute = (route, state) => {
442
+ // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
443
+ // This makes sure that we preserve the original URL for wildcard routes
444
+ if (route !== null && route !== void 0 && route.path) {
445
+ const stateForPath = getStateFromPathRef.current(route.path, configRef.current);
446
+
447
+ if (stateForPath) {
448
+ const focusedRoute = findFocusedRoute(stateForPath);
449
+
450
+ if (focusedRoute && focusedRoute.name === route.name && isEqual(focusedRoute.params, route.params)) {
451
+ return route.path;
452
+ }
453
+ }
454
+ }
455
+
456
+ return getPathFromStateRef.current(state, configRef.current);
457
+ };
458
+
440
459
  if (ref.current) {
441
460
  // We need to record the current metadata on the first render if they aren't set
442
461
  // This will allow the initial state to be in the history entry
443
462
  const state = ref.current.getRootState();
444
463
 
445
464
  if (state) {
446
- var _route$path;
447
-
448
465
  const route = findFocusedRoute(state);
449
- const path = (_route$path = route === null || route === void 0 ? void 0 : route.path) !== null && _route$path !== void 0 ? _route$path : getPathFromStateRef.current(state, configRef.current);
466
+ const path = getPathForRoute(route, state);
450
467
 
451
468
  if (previousStateRef.current === undefined) {
452
469
  previousStateRef.current = state;
@@ -460,8 +477,6 @@ export default function useLinking(ref, {
460
477
  }
461
478
 
462
479
  const onStateChange = async () => {
463
- var _route$path2;
464
-
465
480
  const navigation = ref.current;
466
481
 
467
482
  if (!navigation || !enabled) {
@@ -469,10 +484,15 @@ export default function useLinking(ref, {
469
484
  }
470
485
 
471
486
  const previousState = previousStateRef.current;
472
- const state = navigation.getRootState();
487
+ const state = navigation.getRootState(); // root state may not available, for example when root navigators switch inside the container
488
+
489
+ if (!state) {
490
+ return;
491
+ }
492
+
473
493
  const pendingPath = pendingPopStatePathRef.current;
474
494
  const route = findFocusedRoute(state);
475
- const path = (_route$path2 = route === null || route === void 0 ? void 0 : route.path) !== null && _route$path2 !== void 0 ? _route$path2 : getPathFromStateRef.current(state, configRef.current);
495
+ const path = getPathForRoute(route, state);
476
496
  previousStateRef.current = state;
477
497
  pendingPopStatePathRef.current = undefined; // To detect the kind of state change, we need to:
478
498
  // - Find the common focused navigation state in previous and current state
@@ -1 +1 @@
1
- {"version":3,"sources":["useLinking.tsx"],"names":["findFocusedRoute","getActionFromState","getActionFromStateDefault","getPathFromState","getPathFromStateDefault","getStateFromPath","getStateFromPathDefault","nanoid","React","ServerContext","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","replaceState","go","n","Math","min","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","max","last","pop","removeEventListener","addEventListener","listen","listener","findMatchingState","a","b","undefined","key","aHistoryLength","routes","bHistoryLength","aRoute","bRoute","aChildState","bChildState","series","handling","queue","callback","unshift","linkingHandlers","useLinking","independent","enabled","config","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","indexOf","useState","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","getInitialState","useCallback","value","location","pathname","search","thenable","then","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","navigation","previousIndex","record","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","route","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","addListener"],"mappings":"AAAA,SACEA,gBADF,EAEEC,kBAAkB,IAAIC,yBAFxB,EAGEC,gBAAgB,IAAIC,uBAHtB,EAIEC,gBAAgB,IAAIC,uBAJtB,QAQO,wBARP;AASA,SAASC,MAAT,QAAuB,mBAAvB;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,aAAP,MAA0B,iBAA1B;;AAcA,MAAMC,mBAAmB,GAAG,MAAM;AAChC,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAsB,GAAG,EAA7B,CAFgC,CAIhC;AACA;;AACA,QAAMC,OAAgE,GAAG,EAAzE;;AAEA,QAAMC,SAAS,GAAG,MAAM;AACtB;AACA;AACA;AACAD,IAAAA,OAAO,CAACE,OAAR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a;AAAEF,YAAAA,IAAF;AAAQL,YAAAA;AAAR,WAAb;AACD,SAJD,MAIO,IAAIqH,YAAY,GAAG,CAAnB,EAAsB;AAC3B;AAEA,gBAAMC,SAAS,GAAGzH,OAAO,CAACO,SAAR,CAAkB;AAAEC,YAAAA;AAAF,WAAlB,CAAlB;AACA,gBAAM0B,YAAY,GAAGlC,OAAO,CAACP,KAA7B;;AAEA,cAAI;AACF,gBAAIgI,SAAS,KAAK,CAAC,CAAf,IAAoBA,SAAS,GAAGvF,YAApC,EAAkD;AAChD;AACA,oBAAMlC,OAAO,CAACgB,EAAR,CAAWyG,SAAS,GAAGvF,YAAvB,CAAN;AACD,aAHD,MAGO;AACL;AACA;AACA;AACA,oBAAMlC,OAAO,CAACgB,EAAR,CAAWwG,YAAX,CAAN;AACD,aATC,CAWF;;;AACAxH,YAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,cAAAA,IAAF;AAAQL,cAAAA;AAAR,aAAhB;AACD,WAbD,CAaE,OAAO6G,CAAP,EAAU,CACV;AACD;AACF,SAtBM,MAsBA;AACL;AACAhH,UAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,YAAAA,IAAF;AAAQL,YAAAA;AAAR,WAAhB;AACD;AACF,OA7CD,MA6CO;AACL;AACA;AACAH,QAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,UAAAA,IAAF;AAAQL,UAAAA;AAAR,SAAhB;AACD;AACF,KA7ED,CAvBoB,CAsGpB;AACA;AACA;;;AACA,2BAAO2B,GAAG,CAACoD,OAAX,iDAAO,aAAawC,WAAb,CAAyB,OAAzB,EAAkCpE,MAAM,CAAC6D,aAAD,CAAxC,CAAP;AACD,GA1GD;AA4GA,SAAO;AACL9B,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import {\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n NavigationState,\n ParamListBase,\n} from '@react-navigation/core';\nimport { nanoid } from 'nanoid/non-secure';\nimport * as React from 'react';\n\nimport ServerContext from './ServerContext';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nconst createMemoryHistory = () => {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n if (!items.length || items.findIndex((item) => item.id === id) < 0) {\n // There are two scenarios for creating an array with only one history record:\n // - When loaded id not found in the items array, this function by default will replace\n // the first item. We need to keep only the new updated object, otherwise it will break\n // the page when navigating forward in history.\n // - This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n items = [{ path, state, id }];\n } else {\n items[index] = { path, state, id };\n }\n\n window.history.replaceState({ id }, '', path);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n if (n > 0) {\n // We shouldn't go forward more than available index\n n = Math.min(n, items.length - 1);\n } else if (n < 0) {\n // We shouldn't go back more than the 0 index\n // Otherwise we'll exit the page\n n = index + n < 0 ? -index : n;\n }\n\n if (n === 0) {\n return;\n }\n\n index += n;\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const id = window.history.state?.id;\n const currentIndex = items.findIndex((item) => item.id === id);\n\n // Fix createMemoryHistory.index variable's value\n // as it may go out of sync when navigating in the browser.\n index = Math.max(currentIndex, 0);\n\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n};\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nconst series = (cb: () => Promise<void>) => {\n // Whether we're currently handling a callback\n let handling = false;\n let queue: (() => Promise<void>)[] = [];\n\n const callback = async () => {\n try {\n if (handling) {\n // If we're currently handling a previous event, wait before handling this one\n // Add the callback to the beginning of the queue\n queue.unshift(callback);\n return;\n }\n\n handling = true;\n\n await cb();\n } finally {\n handling = false;\n\n if (queue.length) {\n // If we have queued items, handle the last one\n const last = queue.pop();\n\n last?.();\n }\n }\n };\n\n return callback;\n};\n\nlet linkingHandlers: Symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase> & {\n independent?: boolean;\n};\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n independent,\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options\n) {\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ??\n (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const path = location.pathname + location.search;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${e.message}`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, ref]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path =\n route?.path ?? getPathFromStateRef.current(state, configRef.current);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path =\n route?.path ?? getPathFromStateRef.current(state, configRef.current);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(\n previousState,\n state\n );\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history\n ? focusedState.history.length\n : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (nextIndex !== -1 && nextIndex < currentIndex) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch (e) {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n });\n\n return {\n getInitialState,\n };\n}\n"]}
1
+ {"version":3,"sources":["useLinking.tsx"],"names":["findFocusedRoute","getActionFromState","getActionFromStateDefault","getPathFromState","getPathFromStateDefault","getStateFromPath","getStateFromPathDefault","isEqual","nanoid","React","ServerContext","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","replaceState","go","n","Math","max","min","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","last","pop","removeEventListener","addEventListener","listen","listener","findMatchingState","a","b","undefined","key","aHistoryLength","routes","bHistoryLength","aRoute","bRoute","aChildState","bChildState","series","handling","queue","callback","unshift","linkingHandlers","useLinking","independent","enabled","config","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","indexOf","useState","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","getInitialState","useCallback","value","location","pathname","search","thenable","then","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","navigation","previousIndex","record","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","getPathForRoute","route","stateForPath","focusedRoute","params","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","addListener"],"mappings":"AAAA,SACEA,gBADF,EAEEC,kBAAkB,IAAIC,yBAFxB,EAGEC,gBAAgB,IAAIC,uBAHtB,EAIEC,gBAAgB,IAAIC,uBAJtB,QAQO,wBARP;AASA,OAAOC,OAAP,MAAoB,iBAApB;AACA,SAASC,MAAT,QAAuB,mBAAvB;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,aAAP,MAA0B,iBAA1B;;AAcA,MAAMC,mBAAmB,GAAG,MAAM;AAChC,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAsB,GAAG,EAA7B,CAFgC,CAIhC;AACA;;AACA,QAAMC,OAAgE,GAAG,EAAzE;;AAEA,QAAMC,SAAS,GAAG,MAAM;AACtB;AACA;AACA;AACAD,IAAAA,OAAO,CAACE,OAAR,CAAiBC,EAAD,IAAQ;AACtB,YAAMC,EAAE,GAAGD,EAAE,CAACC,EAAd;;AACAD,MAAAA,EAAE,CAACC,EAAH,GAAQ,MAAMA,EAAE,CAAC,IAAD,CAAhB;AACD,KAHD;AAID,GARD;;AAUA,QAAMC,OAAO,GAAG;AACd,QAAIP,KAAJ,GAAoB;AA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R,SAAhB;AACD;AACF,KAjFD,CAlDoB,CAqIpB;AACA;AACA;;;AACA,2BAAO4B,GAAG,CAACmD,OAAX,iDAAO,aAAa4C,WAAb,CAAyB,OAAzB,EAAkCxE,MAAM,CAACiE,aAAD,CAAxC,CAAP;AACD,GAzID;AA2IA,SAAO;AACLlC,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import {\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n NavigationState,\n ParamListBase,\n} from '@react-navigation/core';\nimport isEqual from 'fast-deep-equal';\nimport { nanoid } from 'nanoid/non-secure';\nimport * as React from 'react';\n\nimport ServerContext from './ServerContext';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nconst createMemoryHistory = () => {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n if (!items.length || items.findIndex((item) => item.id === id) < 0) {\n // There are two scenarios for creating an array with only one history record:\n // - When loaded id not found in the items array, this function by default will replace\n // the first item. We need to keep only the new updated object, otherwise it will break\n // the page when navigating forward in history.\n // - This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n items = [{ path, state, id }];\n index = 0;\n } else {\n items[index] = { path, state, id };\n }\n\n window.history.replaceState({ id }, '', path);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n if (n === 0) {\n return;\n }\n\n // We shouldn't go back more than the 0 index (otherwise we'll exit the page)\n // Or forward more than the available index (or the app will crash)\n index =\n n < 0 ? Math.max(index - n, 0) : Math.min(index + n, items.length - 1);\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const id = window.history.state?.id;\n const currentIndex = items.findIndex((item) => item.id === id);\n\n // Fix createMemoryHistory.index variable's value\n // as it may go out of sync when navigating in the browser.\n index = Math.max(currentIndex, 0);\n\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n};\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nconst series = (cb: () => Promise<void>) => {\n // Whether we're currently handling a callback\n let handling = false;\n let queue: (() => Promise<void>)[] = [];\n\n const callback = async () => {\n try {\n if (handling) {\n // If we're currently handling a previous event, wait before handling this one\n // Add the callback to the beginning of the queue\n queue.unshift(callback);\n return;\n }\n\n handling = true;\n\n await cb();\n } finally {\n handling = false;\n\n if (queue.length) {\n // If we have queued items, handle the last one\n const last = queue.pop();\n\n last?.();\n }\n }\n };\n\n return callback;\n};\n\nlet linkingHandlers: Symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase> & {\n independent?: boolean;\n};\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n independent,\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options\n) {\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ??\n (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const path = location.pathname + location.search;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e\n ? // @ts-expect-error: we're already checking for this\n e.message\n : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, ref]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(\n route.path,\n configRef.current\n );\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual(focusedRoute.params, route.params)\n ) {\n return route.path;\n }\n }\n }\n\n return getPathFromStateRef.current(state, configRef.current);\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(\n previousState,\n state\n );\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history\n ? focusedState.history.length\n : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (nextIndex !== -1 && nextIndex < currentIndex) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch (e) {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n });\n\n return {\n getInitialState,\n };\n}\n"]}
@@ -3,33 +3,37 @@ import * as React from 'react';
3
3
  import { Linking, Platform } from 'react-native';
4
4
  import extractPathFromURL from './extractPathFromURL';
5
5
  let linkingHandlers = [];
6
- export default function useLinking(ref, {
7
- independent,
8
- enabled = true,
9
- prefixes,
10
- filter,
11
- config,
12
- getInitialURL = () => Promise.race([Linking.getInitialURL(), new Promise(resolve => // Timeout in 150ms if `getInitialState` doesn't resolve
13
- // Workaround for https://github.com/facebook/react-native/issues/25675
14
- setTimeout(resolve, 150))]),
15
- subscribe = listener => {
16
- const callback = ({
17
- url
18
- }) => listener(url);
19
-
20
- const subscription = Linking.addEventListener('url', callback);
21
- return () => {
22
- // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
23
- if (subscription !== null && subscription !== void 0 && subscription.remove) {
24
- subscription.remove();
25
- } else {
26
- Linking.removeEventListener('url', callback);
27
- }
28
- };
29
- },
30
- getStateFromPath = getStateFromPathDefault,
31
- getActionFromState = getActionFromStateDefault
32
- }) {
6
+ export default function useLinking(ref, _ref) {
7
+ let {
8
+ independent,
9
+ enabled = true,
10
+ prefixes,
11
+ filter,
12
+ config,
13
+ getInitialURL = () => Promise.race([Linking.getInitialURL(), new Promise(resolve => // Timeout in 150ms if `getInitialState` doesn't resolve
14
+ // Workaround for https://github.com/facebook/react-native/issues/25675
15
+ setTimeout(resolve, 150))]),
16
+ subscribe = listener => {
17
+ const callback = _ref2 => {
18
+ let {
19
+ url
20
+ } = _ref2;
21
+ return listener(url);
22
+ };
23
+
24
+ const subscription = Linking.addEventListener('url', callback);
25
+ return () => {
26
+ // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
27
+ if (subscription !== null && subscription !== void 0 && subscription.remove) {
28
+ subscription.remove();
29
+ } else {
30
+ Linking.removeEventListener('url', callback);
31
+ }
32
+ };
33
+ },
34
+ getStateFromPath = getStateFromPathDefault,
35
+ getActionFromState = getActionFromStateDefault
36
+ } = _ref;
33
37
  React.useEffect(() => {
34
38
  if (process.env.NODE_ENV === 'production') {
35
39
  return undefined;
@@ -139,7 +143,8 @@ export default function useLinking(ref, {
139
143
  } catch (e) {
140
144
  // Ignore any errors from deep linking.
141
145
  // This could happen in case of malformed links, navigation object not being initialized etc.
142
- console.warn(`An error occurred when trying to handle the link '${url}': ${e.message}`);
146
+ console.warn(`An error occurred when trying to handle the link '${url}': ${typeof e === 'object' && e != null && 'message' in e ? // @ts-expect-error: we're already checking for this
147
+ e.message : e}`);
143
148
  }
144
149
  } else {
145
150
  navigation.resetRoot(state);
@@ -1 +1 @@
1
- {"version":3,"sources":["useLinking.native.tsx"],"names":["getActionFromState","getActionFromStateDefault","getStateFromPath","getStateFromPathDefault","React","Linking","Platform","extractPathFromURL","linkingHandlers","useLinking","ref","independent","enabled","prefixes","filter","config","getInitialURL","Promise","race","resolve","setTimeout","subscribe","listener","callback","url","subscription","addEventListener","remove","removeEventListener","useEffect","process","env","NODE_ENV","undefined","length","console","error","OS","join","trim","handler","Symbol","push","index","indexOf","splice","enabledRef","useRef","prefixesRef","filterRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getStateFromURL","useCallback","path","getInitialState","state","then","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","r","routeNames","includes","name","warn","action","dispatch","e","message","resetRoot"],"mappings":"AAAA,SACEA,kBAAkB,IAAIC,yBADxB,EAEEC,gBAAgB,IAAIC,uBAFtB,QAKO,wBALP;AAMA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,cAAlC;AAEA,OAAOC,kBAAP,MAA+B,sBAA/B;AASA,IAAIC,eAAyB,GAAG,EAAhC;AAEA,eAAe,SAASC,UAAT,CACbC,GADa,EAEb;AACEC,EAAAA,WADF;AAEEC,EAAAA,OAAO,GAAG,IAFZ;AAGEC,EAAAA,QAHF;AAIEC,EAAAA,MAJF;AAKEC,EAAAA,MALF;AAMEC,EAAAA,aAAa,GAAG,MACdC,OAAO,CAACC,IAAR,CAAa,CACXb,OAAO,CAACW,aAAR,EADW,EAEX,IAAIC,OAAJ,CAAwBE,OAAD,IACrB;AACA;AACAC,EAAAA,UAAU,CAACD,OAAD,EAAU,GAAV,CAHZ,CAFW,CAAb,CAPJ;AAeEE,EAAAA,SAAS,GAAIC,QAAD,IAAc;AACxB,UAAMC,QAAQ,GAAG,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAA8BF,QAAQ,CAACE,GAAD,CAAvD;;AAEA,UAAMC,YAAY,GAAGpB,OAAO,CAACqB,gBAAR,CAAyB,KAAzB,EAAgCH,QAAhC,CAArB;AAIA,WAAO,MAAM;AACX;AACA,UAAIE,YAAJ,aAAIA,YAAJ,eAAIA,YAAY,CAAEE,MAAlB,EAA0B;AACxBF,QAAAA,YAAY,CAACE,MAAb;AACD,OAFD,MAEO;AACLtB,QAAAA,OAAO,CAACuB,mBAAR,CAA4B,KAA5B,EAAmCL,QAAnC;AACD;AACF,KAPD;AAQD,GA9BH;AA+BErB,EAAAA,gBAAgB,GAAGC,uBA/BrB;AAgCEH,EAAAA,kBAAkB,GAAGC;AAhCvB,CA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EAAqCT,SAAS,CAACI,OAA/C,CAAf;;AAEA,YAAIoB,MAAM,KAAKzC,SAAf,EAA0B;AACxB,cAAI;AACF+B,YAAAA,UAAU,CAACW,QAAX,CAAoBD,MAApB;AACD,WAFD,CAEE,OAAOE,CAAP,EAAU;AACV;AACA;AACAzC,YAAAA,OAAO,CAACsC,IAAR,CACG,qDAAoDjD,GAAI,MAAKoD,CAAC,CAACC,OAAQ,EAD1E;AAGD;AACF,SAVD,MAUO;AACLb,UAAAA,UAAU,CAACc,SAAX,CAAqBnB,KAArB;AACD;AACF;AACF,KApCD;;AAsCA,WAAOtC,SAAS,CAACC,QAAD,CAAhB;AACD,GAxCD,EAwCG,CAACV,OAAD,EAAU2C,eAAV,EAA2B7C,GAA3B,EAAgCW,SAAhC,CAxCH;AA0CA,SAAO;AACLqC,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import {\n getActionFromState as getActionFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n ParamListBase,\n} from '@react-navigation/core';\nimport * as React from 'react';\nimport { Linking, Platform } from 'react-native';\n\nimport extractPathFromURL from './extractPathFromURL';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype Options = LinkingOptions<ParamListBase> & {\n independent?: boolean;\n};\n\nlet linkingHandlers: Symbol[] = [];\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n independent,\n enabled = true,\n prefixes,\n filter,\n config,\n getInitialURL = () =>\n Promise.race([\n Linking.getInitialURL(),\n new Promise<undefined>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(resolve, 150)\n ),\n ]),\n subscribe = (listener) => {\n const callback = ({ url }: { url: string }) => listener(url);\n\n const subscription = Linking.addEventListener('url', callback) as\n | { remove(): void }\n | undefined;\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n Linking.removeEventListener('url', callback);\n }\n };\n },\n getStateFromPath = getStateFromPathDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options\n) {\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n Platform.OS === 'android'\n ? \"- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances\"\n : '',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const prefixesRef = React.useRef(prefixes);\n const filterRef = React.useRef(filter);\n const configRef = React.useRef(config);\n const getInitialURLRef = React.useRef(getInitialURL);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n prefixesRef.current = prefixes;\n filterRef.current = filter;\n configRef.current = config;\n getInitialURLRef.current = getInitialURL;\n getStateFromPathRef.current = getStateFromPath;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const getStateFromURL = React.useCallback(\n (url: string | null | undefined) => {\n if (!url || (filterRef.current && !filterRef.current(url))) {\n return undefined;\n }\n\n const path = extractPathFromURL(prefixesRef.current, url);\n\n return path\n ? getStateFromPathRef.current(path, configRef.current)\n : undefined;\n },\n []\n );\n\n const getInitialState = React.useCallback(() => {\n let state: ResultState | undefined;\n\n if (enabledRef.current) {\n const url = getInitialURLRef.current();\n\n if (url != null && typeof url !== 'string') {\n return url.then((url) => {\n const state = getStateFromURL(url);\n\n return state;\n });\n }\n\n state = getStateFromURL(url);\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(state) : state);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n }, [getStateFromURL]);\n\n React.useEffect(() => {\n const listener = (url: string) => {\n if (!enabled) {\n return;\n }\n\n const navigation = ref.current;\n const state = navigation ? getStateFromURL(url) : undefined;\n\n if (navigation && state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n const action = getActionFromStateRef.current(state, configRef.current);\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${url}': ${e.message}`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n }\n };\n\n return subscribe(listener);\n }, [enabled, getStateFromURL, ref, subscribe]);\n\n return {\n getInitialState,\n };\n}\n"]}
1
+ {"version":3,"sources":["useLinking.native.tsx"],"names":["getActionFromState","getActionFromStateDefault","getStateFromPath","getStateFromPathDefault","React","Linking","Platform","extractPathFromURL","linkingHandlers","useLinking","ref","independent","enabled","prefixes","filter","config","getInitialURL","Promise","race","resolve","setTimeout","subscribe","listener","callback","url","subscription","addEventListener","remove","removeEventListener","useEffect","process","env","NODE_ENV","undefined","length","console","error","OS","join","trim","handler","Symbol","push","index","indexOf","splice","enabledRef","useRef","prefixesRef","filterRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getStateFromURL","useCallback","path","getInitialState","state","then","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","r","routeNames","includes","name","warn","action","dispatch","e","message","resetRoot"],"mappings":"AAAA,SACEA,kBAAkB,IAAIC,yBADxB,EAEEC,gBAAgB,IAAIC,uBAFtB,QAKO,wBALP;AAMA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,cAAlC;AAEA,OAAOC,kBAAP,MAA+B,sBAA/B;AASA,IAAIC,eAAyB,GAAG,EAAhC;AAEA,eAAe,SAASC,UAAT,CACbC,GADa,QAoCb;AAAA,MAlCA;AACEC,IAAAA,WADF;AAEEC,IAAAA,OAAO,GAAG,IAFZ;AAGEC,IAAAA,QAHF;AAIEC,IAAAA,MAJF;AAKEC,IAAAA,MALF;AAMEC,IAAAA,aAAa,GAAG,MACdC,OAAO,CAACC,IAAR,CAAa,CACXb,OAAO,CAACW,aAAR,EADW,EAEX,IAAIC,OAAJ,CAAwBE,OAAD,IACrB;AACA;AACAC,IAAAA,UAAU,CAACD,OAAD,EAAU,GAAV,CAHZ,CAFW,CAAb,CAPJ;AAeEE,IAAAA,SAAS,GAAIC,QAAD,IAAc;AACxB,YAAMC,QAAQ,GAAG;AAAA,YAAC;AAAEC,UAAAA;AAAF,SAAD;AAAA,eAA8BF,QAAQ,CAACE,GAAD,CAAtC;AAAA,OAAjB;;AAEA,YAAMC,YAAY,GAAGpB,OAAO,CAACqB,gBAAR,CAAyB,KAAzB,EAAgCH,QAAhC,CAArB;AAIA,aAAO,MAAM;AACX;AACA,YAAIE,YAAJ,aAAIA,YAAJ,eAAIA,YAAY,CAAEE,MAAlB,EAA0B;AACxBF,UAAA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AS,CAAEK,UAAX,CAAsBC,QAAtB,CAA+BF,CAAC,CAACG,IAAjC,CAAD,CAAzB,CAAJ,EAAuE;AACrErC,UAAAA,OAAO,CAACsC,IAAR,CACE,0SADF;AAGA;AACD;;AAED,cAAMC,MAAM,GAAGrB,qBAAqB,CAACC,OAAtB,CAA8BK,KAA9B,EAAqCT,SAAS,CAACI,OAA/C,CAAf;;AAEA,YAAIoB,MAAM,KAAKzC,SAAf,EAA0B;AACxB,cAAI;AACF+B,YAAAA,UAAU,CAACW,QAAX,CAAoBD,MAApB;AACD,WAFD,CAEE,OAAOE,CAAP,EAAU;AACV;AACA;AACAzC,YAAAA,OAAO,CAACsC,IAAR,CACG,qDAAoDjD,GAAI,MACvD,OAAOoD,CAAP,KAAa,QAAb,IAAyBA,CAAC,IAAI,IAA9B,IAAsC,aAAaA,CAAnD,GACI;AACAA,YAAAA,CAAC,CAACC,OAFN,GAGID,CACL,EANH;AAQD;AACF,SAfD,MAeO;AACLZ,UAAAA,UAAU,CAACc,SAAX,CAAqBnB,KAArB;AACD;AACF;AACF,KAzCD;;AA2CA,WAAOtC,SAAS,CAACC,QAAD,CAAhB;AACD,GA7CD,EA6CG,CAACV,OAAD,EAAU2C,eAAV,EAA2B7C,GAA3B,EAAgCW,SAAhC,CA7CH;AA+CA,SAAO;AACLqC,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import {\n getActionFromState as getActionFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n ParamListBase,\n} from '@react-navigation/core';\nimport * as React from 'react';\nimport { Linking, Platform } from 'react-native';\n\nimport extractPathFromURL from './extractPathFromURL';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype Options = LinkingOptions<ParamListBase> & {\n independent?: boolean;\n};\n\nlet linkingHandlers: Symbol[] = [];\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n independent,\n enabled = true,\n prefixes,\n filter,\n config,\n getInitialURL = () =>\n Promise.race([\n Linking.getInitialURL(),\n new Promise<undefined>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(resolve, 150)\n ),\n ]),\n subscribe = (listener) => {\n const callback = ({ url }: { url: string }) => listener(url);\n\n const subscription = Linking.addEventListener('url', callback) as\n | { remove(): void }\n | undefined;\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n Linking.removeEventListener('url', callback);\n }\n };\n },\n getStateFromPath = getStateFromPathDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options\n) {\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n Platform.OS === 'android'\n ? \"- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances\"\n : '',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const prefixesRef = React.useRef(prefixes);\n const filterRef = React.useRef(filter);\n const configRef = React.useRef(config);\n const getInitialURLRef = React.useRef(getInitialURL);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n prefixesRef.current = prefixes;\n filterRef.current = filter;\n configRef.current = config;\n getInitialURLRef.current = getInitialURL;\n getStateFromPathRef.current = getStateFromPath;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const getStateFromURL = React.useCallback(\n (url: string | null | undefined) => {\n if (!url || (filterRef.current && !filterRef.current(url))) {\n return undefined;\n }\n\n const path = extractPathFromURL(prefixesRef.current, url);\n\n return path\n ? getStateFromPathRef.current(path, configRef.current)\n : undefined;\n },\n []\n );\n\n const getInitialState = React.useCallback(() => {\n let state: ResultState | undefined;\n\n if (enabledRef.current) {\n const url = getInitialURLRef.current();\n\n if (url != null && typeof url !== 'string') {\n return url.then((url) => {\n const state = getStateFromURL(url);\n\n return state;\n });\n }\n\n state = getStateFromURL(url);\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(state) : state);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n }, [getStateFromURL]);\n\n React.useEffect(() => {\n const listener = (url: string) => {\n if (!enabled) {\n return;\n }\n\n const navigation = ref.current;\n const state = navigation ? getStateFromURL(url) : undefined;\n\n if (navigation && state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n const action = getActionFromStateRef.current(state, configRef.current);\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${url}': ${\n typeof e === 'object' && e != null && 'message' in e\n ? // @ts-expect-error: we're already checking for this\n e.message\n : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n }\n };\n\n return subscribe(listener);\n }, [enabled, getStateFromURL, ref, subscribe]);\n\n return {\n getInitialState,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-navigation/native",
3
3
  "description": "React Native integration for React Navigation",
4
- "version": "6.0.4",
4
+ "version": "6.0.8",
5
5
  "keywords": [
6
6
  "react-native",
7
7
  "react-navigation",
@@ -37,8 +37,9 @@
37
37
  "clean": "del lib"
38
38
  },
39
39
  "dependencies": {
40
- "@react-navigation/core": "^6.0.2",
40
+ "@react-navigation/core": "^6.1.1",
41
41
  "escape-string-regexp": "^4.0.0",
42
+ "fast-deep-equal": "^3.1.3",
42
43
  "nanoid": "^3.1.23"
43
44
  },
44
45
  "devDependencies": {
@@ -47,9 +48,9 @@
47
48
  "@types/react-dom": "^17.0.6",
48
49
  "@types/react-native": "~0.64.9",
49
50
  "del-cli": "^3.0.1",
50
- "react": "~16.13.1",
51
- "react-dom": "^16.13.1",
52
- "react-native": "~0.63.4",
51
+ "react": "17.0.1",
52
+ "react-dom": "17.0.1",
53
+ "react-native": "~0.64.3",
53
54
  "react-native-builder-bob": "^0.18.1",
54
55
  "typescript": "^4.3.2"
55
56
  },
@@ -71,5 +72,5 @@
71
72
  ]
72
73
  ]
73
74
  },
74
- "gitHead": "6a19be7dae997fc23ac9475040a17fb2db4ebd52"
75
+ "gitHead": "4cddbce150413c15db93897c76b813f436f5186d"
75
76
  }
@@ -7,7 +7,8 @@ export type ServerContextType = {
7
7
  };
8
8
  };
9
9
 
10
- const ServerContext =
11
- React.createContext<ServerContextType | undefined>(undefined);
10
+ const ServerContext = React.createContext<ServerContextType | undefined>(
11
+ undefined
12
+ );
12
13
 
13
14
  export default ServerContext;
@@ -189,7 +189,12 @@ export default function useLinking(
189
189
  // Ignore any errors from deep linking.
190
190
  // This could happen in case of malformed links, navigation object not being initialized etc.
191
191
  console.warn(
192
- `An error occurred when trying to handle the link '${url}': ${e.message}`
192
+ `An error occurred when trying to handle the link '${url}': ${
193
+ typeof e === 'object' && e != null && 'message' in e
194
+ ? // @ts-expect-error: we're already checking for this
195
+ e.message
196
+ : e
197
+ }`
193
198
  );
194
199
  }
195
200
  } else {