@react-navigation/native 6.0.16 → 6.1.1

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 (137) hide show
  1. package/lib/commonjs/Link.js +2 -12
  2. package/lib/commonjs/Link.js.map +1 -1
  3. package/lib/commonjs/LinkingContext.js +0 -4
  4. package/lib/commonjs/LinkingContext.js.map +1 -1
  5. package/lib/commonjs/NavigationContainer.js +9 -31
  6. package/lib/commonjs/NavigationContainer.js.map +1 -1
  7. package/lib/commonjs/ServerContainer.js +2 -12
  8. package/lib/commonjs/ServerContainer.js.map +1 -1
  9. package/lib/commonjs/ServerContext.js +0 -4
  10. package/lib/commonjs/ServerContext.js.map +1 -1
  11. package/lib/commonjs/createMemoryHistory.js +36 -53
  12. package/lib/commonjs/createMemoryHistory.js.map +1 -1
  13. package/lib/commonjs/extractPathFromURL.js +2 -8
  14. package/lib/commonjs/extractPathFromURL.js.map +1 -1
  15. package/lib/commonjs/index.js +0 -17
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/theming/DarkTheme.js.map +1 -1
  18. package/lib/commonjs/theming/DefaultTheme.js.map +1 -1
  19. package/lib/commonjs/theming/ThemeContext.js +0 -6
  20. package/lib/commonjs/theming/ThemeContext.js.map +1 -1
  21. package/lib/commonjs/theming/ThemeProvider.js +0 -6
  22. package/lib/commonjs/theming/ThemeProvider.js.map +1 -1
  23. package/lib/commonjs/theming/useTheme.js +0 -6
  24. package/lib/commonjs/theming/useTheme.js.map +1 -1
  25. package/lib/commonjs/types.js.map +1 -1
  26. package/lib/commonjs/useBackButton.js +0 -9
  27. package/lib/commonjs/useBackButton.js.map +1 -1
  28. package/lib/commonjs/useDocumentTitle.js +1 -12
  29. package/lib/commonjs/useDocumentTitle.js.map +1 -1
  30. package/lib/commonjs/useDocumentTitle.native.js +2 -2
  31. package/lib/commonjs/useDocumentTitle.native.js.map +1 -1
  32. package/lib/commonjs/useLinkBuilder.js +5 -15
  33. package/lib/commonjs/useLinkBuilder.js.map +1 -1
  34. package/lib/commonjs/useLinkProps.js +8 -24
  35. package/lib/commonjs/useLinkProps.js.map +1 -1
  36. package/lib/commonjs/useLinkTo.js +0 -12
  37. package/lib/commonjs/useLinkTo.js.map +1 -1
  38. package/lib/commonjs/useLinking.js +35 -79
  39. package/lib/commonjs/useLinking.js.map +1 -1
  40. package/lib/commonjs/useLinking.native.js +9 -36
  41. package/lib/commonjs/useLinking.native.js.map +1 -1
  42. package/lib/commonjs/useScrollToTop.js +48 -47
  43. package/lib/commonjs/useScrollToTop.js.map +1 -1
  44. package/lib/commonjs/useThenable.js +2 -9
  45. package/lib/commonjs/useThenable.js.map +1 -1
  46. package/lib/module/Link.js +2 -6
  47. package/lib/module/Link.js.map +1 -1
  48. package/lib/module/LinkingContext.js.map +1 -1
  49. package/lib/module/NavigationContainer.js +9 -18
  50. package/lib/module/NavigationContainer.js.map +1 -1
  51. package/lib/module/ServerContainer.js +2 -5
  52. package/lib/module/ServerContainer.js.map +1 -1
  53. package/lib/module/ServerContext.js.map +1 -1
  54. package/lib/module/createMemoryHistory.js +36 -51
  55. package/lib/module/createMemoryHistory.js.map +1 -1
  56. package/lib/module/extractPathFromURL.js +2 -5
  57. package/lib/module/extractPathFromURL.js.map +1 -1
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/theming/DarkTheme.js.map +1 -1
  60. package/lib/module/theming/DefaultTheme.js.map +1 -1
  61. package/lib/module/theming/ThemeContext.js.map +1 -1
  62. package/lib/module/theming/ThemeProvider.js.map +1 -1
  63. package/lib/module/theming/useTheme.js.map +1 -1
  64. package/lib/module/types.js.map +1 -1
  65. package/lib/module/useBackButton.js +0 -3
  66. package/lib/module/useBackButton.js.map +1 -1
  67. package/lib/module/useDocumentTitle.js +1 -9
  68. package/lib/module/useDocumentTitle.js.map +1 -1
  69. package/lib/module/useDocumentTitle.native.js +2 -1
  70. package/lib/module/useDocumentTitle.native.js.map +1 -1
  71. package/lib/module/useLinkBuilder.js +5 -9
  72. package/lib/module/useLinkBuilder.js.map +1 -1
  73. package/lib/module/useLinkProps.js +8 -16
  74. package/lib/module/useLinkProps.js.map +1 -1
  75. package/lib/module/useLinkTo.js +0 -5
  76. package/lib/module/useLinkTo.js.map +1 -1
  77. package/lib/module/useLinking.js +35 -70
  78. package/lib/module/useLinking.js.map +1 -1
  79. package/lib/module/useLinking.native.js +9 -26
  80. package/lib/module/useLinking.native.js.map +1 -1
  81. package/lib/module/useScrollToTop.js +48 -43
  82. package/lib/module/useScrollToTop.js.map +1 -1
  83. package/lib/module/useThenable.js +2 -5
  84. package/lib/module/useThenable.js.map +1 -1
  85. package/lib/typescript/src/Link.d.ts +1 -0
  86. package/lib/typescript/src/Link.d.ts.map +1 -0
  87. package/lib/typescript/src/LinkingContext.d.ts +1 -0
  88. package/lib/typescript/src/LinkingContext.d.ts.map +1 -0
  89. package/lib/typescript/src/NavigationContainer.d.ts +1 -0
  90. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -0
  91. package/lib/typescript/src/ServerContainer.d.ts +1 -0
  92. package/lib/typescript/src/ServerContainer.d.ts.map +1 -0
  93. package/lib/typescript/src/ServerContext.d.ts +1 -0
  94. package/lib/typescript/src/ServerContext.d.ts.map +1 -0
  95. package/lib/typescript/src/__mocks__/window.d.ts +1 -0
  96. package/lib/typescript/src/__mocks__/window.d.ts.map +1 -0
  97. package/lib/typescript/src/createMemoryHistory.d.ts +1 -0
  98. package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -0
  99. package/lib/typescript/src/extractPathFromURL.d.ts +1 -0
  100. package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -0
  101. package/lib/typescript/src/index.d.ts +1 -0
  102. package/lib/typescript/src/index.d.ts.map +1 -0
  103. package/lib/typescript/src/theming/DarkTheme.d.ts +1 -0
  104. package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -0
  105. package/lib/typescript/src/theming/DefaultTheme.d.ts +1 -0
  106. package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -0
  107. package/lib/typescript/src/theming/ThemeContext.d.ts +1 -0
  108. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -0
  109. package/lib/typescript/src/theming/ThemeProvider.d.ts +1 -0
  110. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -0
  111. package/lib/typescript/src/theming/useTheme.d.ts +1 -0
  112. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -0
  113. package/lib/typescript/src/types.d.ts +1 -0
  114. package/lib/typescript/src/types.d.ts.map +1 -0
  115. package/lib/typescript/src/useBackButton.d.ts +1 -0
  116. package/lib/typescript/src/useBackButton.d.ts.map +1 -0
  117. package/lib/typescript/src/useDocumentTitle.d.ts +1 -0
  118. package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -0
  119. package/lib/typescript/src/useDocumentTitle.native.d.ts +1 -0
  120. package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -0
  121. package/lib/typescript/src/useLinkBuilder.d.ts +1 -0
  122. package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -0
  123. package/lib/typescript/src/useLinkProps.d.ts +1 -0
  124. package/lib/typescript/src/useLinkProps.d.ts.map +1 -0
  125. package/lib/typescript/src/useLinkTo.d.ts +1 -0
  126. package/lib/typescript/src/useLinkTo.d.ts.map +1 -0
  127. package/lib/typescript/src/useLinking.d.ts +1 -0
  128. package/lib/typescript/src/useLinking.d.ts.map +1 -0
  129. package/lib/typescript/src/useLinking.native.d.ts +1 -0
  130. package/lib/typescript/src/useLinking.native.d.ts.map +1 -0
  131. package/lib/typescript/src/useScrollToTop.d.ts +1 -0
  132. package/lib/typescript/src/useScrollToTop.d.ts.map +1 -0
  133. package/lib/typescript/src/useThenable.d.ts +1 -0
  134. package/lib/typescript/src/useThenable.d.ts.map +1 -0
  135. package/package.json +4 -4
  136. package/src/createMemoryHistory.tsx +10 -2
  137. package/src/useScrollToTop.tsx +52 -38
@@ -48,3 +48,4 @@ export default function useLinking(ref: React.RefObject<NavigationContainerRef<P
48
48
  }) | undefined>;
49
49
  };
50
50
  export {};
51
+ //# sourceMappingURL=useLinking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLinking.d.ts","sourceRoot":"","sources":["../../../src/useLinking.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,sBAAsB,EAEtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAiF9C,aAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,GAAG;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,WAAW,EACX,OAAc,EACd,MAAM,EACN,gBAA0C,EAC1C,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuTX"}
@@ -48,3 +48,4 @@ export default function useLinking(ref: React.RefObject<NavigationContainerRef<P
48
48
  }) | undefined>;
49
49
  };
50
50
  export {};
51
+ //# sourceMappingURL=useLinking.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLinking.native.d.ts","sourceRoot":"","sources":["../../../src/useLinking.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,aAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,GAAG;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,WAAW,EACX,OAAc,EACd,QAAQ,EACR,MAAM,EACN,MAAM,EACN,aAQI,EACJ,SAkBC,EACD,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4JX"}
@@ -23,3 +23,4 @@ declare type ScrollableWrapper = {
23
23
  } | ScrollableView;
24
24
  export default function useScrollToTop(ref: React.RefObject<ScrollableWrapper>): void;
25
25
  export {};
26
+ //# sourceMappingURL=useScrollToTop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollToTop.d.ts","sourceRoot":"","sources":["../../../src/useScrollToTop.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,aAAK,aAAa,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpE,aAAK,cAAc,GACf;IAAE,WAAW,IAAI,IAAI,CAAA;CAAE,GACvB;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,GAC1C;IAAE,cAAc,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAC1E;IAAE,uBAAuB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,CAAC;AAE9D,aAAK,iBAAiB,GAClB;IAAE,kBAAkB,IAAI,KAAK,CAAC,SAAS,CAAA;CAAE,GACzC;IAAE,OAAO,IAAI,cAAc,CAAA;CAAE,GAC7B,cAAc,CAAC;AA8BnB,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,QAgExC"}
@@ -1 +1,2 @@
1
1
  export default function useThenable<T>(create: () => PromiseLike<T>): [boolean, T | undefined];
2
+ //# sourceMappingURL=useThenable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useThenable.d.ts","sourceRoot":"","sources":["../../../src/useThenable.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,4BAsClE"}
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.16",
4
+ "version": "6.1.1",
5
5
  "keywords": [
6
6
  "react-native",
7
7
  "react-navigation",
@@ -37,7 +37,7 @@
37
37
  "clean": "del lib"
38
38
  },
39
39
  "dependencies": {
40
- "@react-navigation/core": "^6.4.3",
40
+ "@react-navigation/core": "^6.4.5",
41
41
  "escape-string-regexp": "^4.0.0",
42
42
  "fast-deep-equal": "^3.1.3",
43
43
  "nanoid": "^3.1.23"
@@ -51,7 +51,7 @@
51
51
  "react": "18.0.0",
52
52
  "react-dom": "18.0.0",
53
53
  "react-native": "0.69.5",
54
- "react-native-builder-bob": "^0.18.1",
54
+ "react-native-builder-bob": "^0.20.3",
55
55
  "typescript": "^4.7.4"
56
56
  },
57
57
  "peerDependencies": {
@@ -72,5 +72,5 @@
72
72
  ]
73
73
  ]
74
74
  },
75
- "gitHead": "4e29403ec63d9304561e296667f6cf15806c316b"
75
+ "gitHead": "2b22d3ea9ca99bc298f4fb48ae9808b65aa25620"
76
76
  }
@@ -84,6 +84,10 @@ export default function createMemoryHistory() {
84
84
 
85
85
  const id = window.history.state?.id ?? nanoid();
86
86
 
87
+ // Need to keep the hash part of the path if there was no previous history entry
88
+ // or the previous history entry had the same path
89
+ let pathWithHash = path;
90
+
87
91
  if (!items.length || items.findIndex((item) => item.id === id) < 0) {
88
92
  // There are two scenarios for creating an array with only one history record:
89
93
  // - When loaded id not found in the items array, this function by default will replace
@@ -91,13 +95,17 @@ export default function createMemoryHistory() {
91
95
  // the page when navigating forward in history.
92
96
  // - This is the first time any state modifications are done
93
97
  // So we need to push the entry as there's nothing to replace
94
- items = [{ path, state, id }];
98
+ pathWithHash = pathWithHash + location.hash;
99
+ items = [{ path: pathWithHash, state, id }];
95
100
  index = 0;
96
101
  } else {
102
+ if (items[index].path === path) {
103
+ pathWithHash = pathWithHash + location.hash;
104
+ }
97
105
  items[index] = { path, state, id };
98
106
  }
99
107
 
100
- window.history.replaceState({ id }, '', path);
108
+ window.history.replaceState({ id }, '', pathWithHash);
101
109
  },
102
110
 
103
111
  // `history.go(n)` is asynchronous, there are couple of things to keep in mind:
@@ -1,4 +1,9 @@
1
- import { EventArg, useNavigation, useRoute } from '@react-navigation/core';
1
+ import {
2
+ EventArg,
3
+ NavigationProp,
4
+ useNavigation,
5
+ useRoute,
6
+ } from '@react-navigation/core';
2
7
  import * as React from 'react';
3
8
 
4
9
  type ScrollOptions = { x?: number; y?: number; animated?: boolean };
@@ -49,53 +54,62 @@ export default function useScrollToTop(
49
54
  const route = useRoute();
50
55
 
51
56
  React.useEffect(() => {
52
- let current = navigation;
57
+ let tabNavigations: NavigationProp<ReactNavigation.RootParamList>[] = [];
58
+ let currentNavigation = navigation;
53
59
 
54
- // The screen might be inside another navigator such as stack nested in tabs
55
- // We need to find the closest tab navigator and add the listener there
56
- while (current && current.getState().type !== 'tab') {
57
- current = current.getParent();
60
+ // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them
61
+ // So we need to find all the parent tab navigators and add the listeners there
62
+ while (currentNavigation) {
63
+ if (currentNavigation.getState().type === 'tab') {
64
+ tabNavigations.push(currentNavigation);
65
+ }
66
+
67
+ currentNavigation = currentNavigation.getParent();
58
68
  }
59
69
 
60
- if (!current) {
70
+ if (tabNavigations.length === 0) {
61
71
  return;
62
72
  }
63
73
 
64
- const unsubscribe = current.addListener(
65
- // We don't wanna import tab types here to avoid extra deps
66
- // in addition, there are multiple tab implementations
67
- // @ts-expect-error
68
- 'tabPress',
69
- (e: EventArg<'tabPress', true>) => {
70
- // We should scroll to top only when the screen is focused
71
- const isFocused = navigation.isFocused();
74
+ const unsubscribers = tabNavigations.map((tab) => {
75
+ return tab.addListener(
76
+ // We don't wanna import tab types here to avoid extra deps
77
+ // in addition, there are multiple tab implementations
78
+ // @ts-expect-error
79
+ 'tabPress',
80
+ (e: EventArg<'tabPress', true>) => {
81
+ // We should scroll to top only when the screen is focused
82
+ const isFocused = navigation.isFocused();
72
83
 
73
- // In a nested stack navigator, tab press resets the stack to first screen
74
- // So we should scroll to top only when we are on first screen
75
- const isFirst =
76
- navigation === current ||
77
- navigation.getState().routes[0].key === route.key;
84
+ // In a nested stack navigator, tab press resets the stack to first screen
85
+ // So we should scroll to top only when we are on first screen
86
+ const isFirst =
87
+ tabNavigations.includes(navigation) ||
88
+ navigation.getState().routes[0].key === route.key;
78
89
 
79
- // Run the operation in the next frame so we're sure all listeners have been run
80
- // This is necessary to know if preventDefault() has been called
81
- requestAnimationFrame(() => {
82
- const scrollable = getScrollableNode(ref) as ScrollableWrapper;
90
+ // Run the operation in the next frame so we're sure all listeners have been run
91
+ // This is necessary to know if preventDefault() has been called
92
+ requestAnimationFrame(() => {
93
+ const scrollable = getScrollableNode(ref) as ScrollableWrapper;
83
94
 
84
- if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
85
- if ('scrollToTop' in scrollable) {
86
- scrollable.scrollToTop();
87
- } else if ('scrollTo' in scrollable) {
88
- scrollable.scrollTo({ x: 0, y: 0, animated: true });
89
- } else if ('scrollToOffset' in scrollable) {
90
- scrollable.scrollToOffset({ offset: 0, animated: true });
91
- } else if ('scrollResponderScrollTo' in scrollable) {
92
- scrollable.scrollResponderScrollTo({ y: 0, animated: true });
95
+ if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
96
+ if ('scrollToTop' in scrollable) {
97
+ scrollable.scrollToTop();
98
+ } else if ('scrollTo' in scrollable) {
99
+ scrollable.scrollTo({ y: 0, animated: true });
100
+ } else if ('scrollToOffset' in scrollable) {
101
+ scrollable.scrollToOffset({ offset: 0, animated: true });
102
+ } else if ('scrollResponderScrollTo' in scrollable) {
103
+ scrollable.scrollResponderScrollTo({ y: 0, animated: true });
104
+ }
93
105
  }
94
- }
95
- });
96
- }
97
- );
106
+ });
107
+ }
108
+ );
109
+ });
98
110
 
99
- return unsubscribe;
111
+ return () => {
112
+ unsubscribers.forEach((unsubscribe) => unsubscribe());
113
+ };
100
114
  }, [navigation, ref, route.key]);
101
115
  }