@react-navigation/native 6.1.6 → 7.0.0-alpha.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 (189) hide show
  1. package/lib/commonjs/Link.js +19 -9
  2. package/lib/commonjs/Link.js.map +1 -1
  3. package/lib/commonjs/LinkingContext.js +2 -3
  4. package/lib/commonjs/LinkingContext.js.map +1 -1
  5. package/lib/commonjs/NavigationContainer.js +19 -32
  6. package/lib/commonjs/NavigationContainer.js.map +1 -1
  7. package/lib/commonjs/ServerContainer.js +5 -6
  8. package/lib/commonjs/ServerContainer.js.map +1 -1
  9. package/lib/commonjs/ServerContext.js +2 -3
  10. package/lib/commonjs/ServerContext.js.map +1 -1
  11. package/lib/commonjs/createMemoryHistory.js +1 -1
  12. package/lib/commonjs/createMemoryHistory.js.map +1 -1
  13. package/lib/commonjs/createStaticNavigation.js +38 -0
  14. package/lib/commonjs/createStaticNavigation.js.map +1 -0
  15. package/lib/commonjs/extractPathFromURL.js +1 -1
  16. package/lib/commonjs/extractPathFromURL.js.map +1 -1
  17. package/lib/commonjs/index.js +28 -29
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/theming/DarkTheme.js +5 -4
  20. package/lib/commonjs/theming/DarkTheme.js.map +1 -1
  21. package/lib/commonjs/theming/DefaultTheme.js +5 -4
  22. package/lib/commonjs/theming/DefaultTheme.js.map +1 -1
  23. package/lib/commonjs/theming/ThemeContext.js +4 -6
  24. package/lib/commonjs/theming/ThemeContext.js.map +1 -1
  25. package/lib/commonjs/theming/ThemeProvider.js +3 -4
  26. package/lib/commonjs/theming/ThemeProvider.js.map +1 -1
  27. package/lib/commonjs/theming/fonts.js +66 -0
  28. package/lib/commonjs/theming/fonts.js.map +1 -0
  29. package/lib/commonjs/theming/useTheme.js +3 -4
  30. package/lib/commonjs/theming/useTheme.js.map +1 -1
  31. package/lib/commonjs/useBackButton.js +1 -1
  32. package/lib/commonjs/useBackButton.js.map +1 -1
  33. package/lib/commonjs/useDocumentTitle.js +1 -1
  34. package/lib/commonjs/useDocumentTitle.js.map +1 -1
  35. package/lib/commonjs/useDocumentTitle.native.js +1 -1
  36. package/lib/commonjs/useDocumentTitle.native.js.map +1 -1
  37. package/lib/commonjs/useLinkProps.js +20 -19
  38. package/lib/commonjs/useLinkProps.js.map +1 -1
  39. package/lib/commonjs/{useLinkBuilder.js → useLinkTools.js} +25 -8
  40. package/lib/commonjs/useLinkTools.js.map +1 -0
  41. package/lib/commonjs/useLinking.js +7 -9
  42. package/lib/commonjs/useLinking.js.map +1 -1
  43. package/lib/commonjs/useLinking.native.js +6 -8
  44. package/lib/commonjs/useLinking.native.js.map +1 -1
  45. package/lib/commonjs/useScrollToTop.js +1 -1
  46. package/lib/commonjs/useScrollToTop.js.map +1 -1
  47. package/lib/commonjs/useThenable.js +1 -1
  48. package/lib/commonjs/useThenable.js.map +1 -1
  49. package/lib/module/Link.js +18 -7
  50. package/lib/module/Link.js.map +1 -1
  51. package/lib/module/LinkingContext.js +1 -2
  52. package/lib/module/LinkingContext.js.map +1 -1
  53. package/lib/module/NavigationContainer.js +11 -23
  54. package/lib/module/NavigationContainer.js.map +1 -1
  55. package/lib/module/ServerContainer.js +2 -2
  56. package/lib/module/ServerContainer.js.map +1 -1
  57. package/lib/module/ServerContext.js +1 -2
  58. package/lib/module/ServerContext.js.map +1 -1
  59. package/lib/module/createMemoryHistory.js +1 -1
  60. package/lib/module/createMemoryHistory.js.map +1 -1
  61. package/lib/module/createStaticNavigation.js +30 -0
  62. package/lib/module/createStaticNavigation.js.map +1 -0
  63. package/lib/module/extractPathFromURL.js +1 -1
  64. package/lib/module/extractPathFromURL.js.map +1 -1
  65. package/lib/module/index.js +12 -12
  66. package/lib/module/index.js.map +1 -1
  67. package/lib/module/theming/DarkTheme.js +4 -3
  68. package/lib/module/theming/DarkTheme.js.map +1 -1
  69. package/lib/module/theming/DefaultTheme.js +4 -3
  70. package/lib/module/theming/DefaultTheme.js.map +1 -1
  71. package/lib/module/theming/ThemeContext.js +2 -3
  72. package/lib/module/theming/ThemeContext.js.map +1 -1
  73. package/lib/module/theming/ThemeProvider.js +2 -2
  74. package/lib/module/theming/ThemeProvider.js.map +1 -1
  75. package/lib/module/theming/fonts.js +59 -0
  76. package/lib/module/theming/fonts.js.map +1 -0
  77. package/lib/module/theming/useTheme.js +2 -2
  78. package/lib/module/theming/useTheme.js.map +1 -1
  79. package/lib/module/useBackButton.js +1 -1
  80. package/lib/module/useBackButton.js.map +1 -1
  81. package/lib/module/useDocumentTitle.js +1 -1
  82. package/lib/module/useDocumentTitle.js.map +1 -1
  83. package/lib/module/useDocumentTitle.native.js +1 -1
  84. package/lib/module/useDocumentTitle.native.js.map +1 -1
  85. package/lib/module/useLinkProps.js +19 -17
  86. package/lib/module/useLinkProps.js.map +1 -1
  87. package/lib/module/{useLinkBuilder.js → useLinkTools.js} +24 -6
  88. package/lib/module/useLinkTools.js.map +1 -0
  89. package/lib/module/useLinking.js +6 -8
  90. package/lib/module/useLinking.js.map +1 -1
  91. package/lib/module/useLinking.native.js +6 -7
  92. package/lib/module/useLinking.native.js.map +1 -1
  93. package/lib/module/useScrollToTop.js +1 -1
  94. package/lib/module/useScrollToTop.js.map +1 -1
  95. package/lib/module/useThenable.js +1 -1
  96. package/lib/module/useThenable.js.map +1 -1
  97. package/lib/typescript/src/Link.d.ts +8 -9
  98. package/lib/typescript/src/Link.d.ts.map +1 -1
  99. package/lib/typescript/src/LinkingContext.d.ts +1 -2
  100. package/lib/typescript/src/LinkingContext.d.ts.map +1 -1
  101. package/lib/typescript/src/NavigationContainer.d.ts +3 -5
  102. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -1
  103. package/lib/typescript/src/ServerContainer.d.ts +1 -2
  104. package/lib/typescript/src/ServerContainer.d.ts.map +1 -1
  105. package/lib/typescript/src/ServerContext.d.ts +2 -3
  106. package/lib/typescript/src/ServerContext.d.ts.map +1 -1
  107. package/lib/typescript/src/__mocks__/createStackNavigator.d.ts +56 -0
  108. package/lib/typescript/src/__mocks__/createStackNavigator.d.ts.map +1 -0
  109. package/lib/typescript/src/__mocks__/window.d.ts +1 -2
  110. package/lib/typescript/src/__mocks__/window.d.ts.map +1 -1
  111. package/lib/typescript/src/createMemoryHistory.d.ts +2 -2
  112. package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -1
  113. package/lib/typescript/src/createStaticNavigation.d.ts +20 -0
  114. package/lib/typescript/src/createStaticNavigation.d.ts.map +1 -0
  115. package/lib/typescript/src/extractPathFromURL.d.ts +1 -1
  116. package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -1
  117. package/lib/typescript/src/index.d.ts +12 -12
  118. package/lib/typescript/src/index.d.ts.map +1 -1
  119. package/lib/typescript/src/theming/DarkTheme.d.ts +1 -2
  120. package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -1
  121. package/lib/typescript/src/theming/DefaultTheme.d.ts +1 -2
  122. package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -1
  123. package/lib/typescript/src/theming/ThemeContext.d.ts +1 -2
  124. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
  125. package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
  126. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
  127. package/lib/typescript/src/theming/fonts.d.ts +53 -0
  128. package/lib/typescript/src/theming/fonts.d.ts.map +1 -0
  129. package/lib/typescript/src/theming/useTheme.d.ts +1 -1
  130. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
  131. package/lib/typescript/src/types.d.ts +15 -4
  132. package/lib/typescript/src/types.d.ts.map +1 -1
  133. package/lib/typescript/src/useBackButton.d.ts +1 -1
  134. package/lib/typescript/src/useBackButton.d.ts.map +1 -1
  135. package/lib/typescript/src/useDocumentTitle.d.ts +1 -1
  136. package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -1
  137. package/lib/typescript/src/useDocumentTitle.native.d.ts +1 -1
  138. package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -1
  139. package/lib/typescript/src/useLinkProps.d.ts +17 -7
  140. package/lib/typescript/src/useLinkProps.d.ts.map +1 -1
  141. package/lib/typescript/src/useLinkTools.d.ts +33 -0
  142. package/lib/typescript/src/useLinkTools.d.ts.map +1 -0
  143. package/lib/typescript/src/useLinking.d.ts +2 -4
  144. package/lib/typescript/src/useLinking.d.ts.map +1 -1
  145. package/lib/typescript/src/useLinking.native.d.ts +2 -4
  146. package/lib/typescript/src/useLinking.native.d.ts.map +1 -1
  147. package/lib/typescript/src/useScrollToTop.d.ts +4 -4
  148. package/lib/typescript/src/useScrollToTop.d.ts.map +1 -1
  149. package/lib/typescript/src/useThenable.d.ts +1 -1
  150. package/lib/typescript/src/useThenable.d.ts.map +1 -1
  151. package/package.json +11 -11
  152. package/src/Link.tsx +26 -16
  153. package/src/LinkingContext.tsx +1 -3
  154. package/src/NavigationContainer.tsx +14 -29
  155. package/src/ServerContainer.tsx +2 -2
  156. package/src/ServerContext.tsx +1 -3
  157. package/src/__mocks__/createStackNavigator.tsx +19 -0
  158. package/src/__mocks__/window.tsx +1 -3
  159. package/src/createMemoryHistory.tsx +1 -1
  160. package/src/createStaticNavigation.tsx +47 -0
  161. package/src/extractPathFromURL.tsx +1 -1
  162. package/src/index.tsx +12 -12
  163. package/src/theming/DarkTheme.tsx +3 -3
  164. package/src/theming/DefaultTheme.tsx +3 -3
  165. package/src/theming/ThemeContext.tsx +2 -4
  166. package/src/theming/ThemeProvider.tsx +2 -2
  167. package/src/theming/fonts.tsx +63 -0
  168. package/src/theming/useTheme.tsx +2 -2
  169. package/src/types.tsx +22 -0
  170. package/src/useBackButton.tsx +1 -1
  171. package/src/useDocumentTitle.native.tsx +1 -1
  172. package/src/useDocumentTitle.tsx +1 -1
  173. package/src/useLinkProps.tsx +49 -33
  174. package/src/{useLinkBuilder.tsx → useLinkTools.tsx} +33 -4
  175. package/src/useLinking.native.tsx +8 -8
  176. package/src/useLinking.tsx +8 -9
  177. package/src/useScrollToTop.tsx +1 -3
  178. package/src/useThenable.tsx +1 -1
  179. package/lib/commonjs/useLinkBuilder.js.map +0 -1
  180. package/lib/commonjs/useLinkTo.js +0 -45
  181. package/lib/commonjs/useLinkTo.js.map +0 -1
  182. package/lib/module/useLinkBuilder.js.map +0 -1
  183. package/lib/module/useLinkTo.js +0 -36
  184. package/lib/module/useLinkTo.js.map +0 -1
  185. package/lib/typescript/src/useLinkBuilder.d.ts +0 -6
  186. package/lib/typescript/src/useLinkBuilder.d.ts.map +0 -1
  187. package/lib/typescript/src/useLinkTo.d.ts +0 -9
  188. package/lib/typescript/src/useLinkTo.d.ts.map +0 -1
  189. package/src/useLinkTo.tsx +0 -71
@@ -10,14 +10,14 @@ import {
10
10
  } from '@react-navigation/core';
11
11
  import * as React from 'react';
12
12
 
13
- import LinkingContext from './LinkingContext';
14
- import DefaultTheme from './theming/DefaultTheme';
15
- import ThemeProvider from './theming/ThemeProvider';
13
+ import { LinkingContext } from './LinkingContext';
14
+ import { DefaultTheme } from './theming/DefaultTheme';
15
+ import { ThemeProvider } from './theming/ThemeProvider';
16
16
  import type { DocumentTitleOptions, LinkingOptions, Theme } from './types';
17
- import useBackButton from './useBackButton';
18
- import useDocumentTitle from './useDocumentTitle';
19
- import useLinking from './useLinking';
20
- import useThenable from './useThenable';
17
+ import { useBackButton } from './useBackButton';
18
+ import { useDocumentTitle } from './useDocumentTitle';
19
+ import { useLinking } from './useLinking';
20
+ import { useThenable } from './useThenable';
21
21
 
22
22
  declare global {
23
23
  var REACT_NAVIGATION_DEVTOOLS: WeakMap<
@@ -33,7 +33,6 @@ type Props<ParamList extends {}> = NavigationContainerProps & {
33
33
  linking?: LinkingOptions<ParamList>;
34
34
  fallback?: React.ReactNode;
35
35
  documentTitle?: DocumentTitleOptions;
36
- onReady?: () => void;
37
36
  };
38
37
 
39
38
  /**
@@ -43,6 +42,7 @@ type Props<ParamList extends {}> = NavigationContainerProps & {
43
42
  * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).
44
43
  * @param props.onReady Callback which is called after the navigation tree mounts.
45
44
  * @param props.onStateChange Callback which is called with the latest navigation state when it changes.
45
+ * @param props.onUnhandledAction Callback which is called when an action is not handled.
46
46
  * @param props.theme Theme object for the navigators.
47
47
  * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.
48
48
  * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.
@@ -56,7 +56,6 @@ function NavigationContainerInner(
56
56
  linking,
57
57
  fallback = null,
58
58
  documentTitle,
59
- onReady,
60
59
  ...rest
61
60
  }: Props<ParamListBase>,
62
61
  ref?: React.Ref<NavigationContainerRef<ParamListBase> | null>
@@ -74,7 +73,6 @@ function NavigationContainerInner(
74
73
  useDocumentTitle(refContainer, documentTitle);
75
74
 
76
75
  const { getInitialState } = useLinking(refContainer, {
77
- independent: rest.independent,
78
76
  enabled: isLinkingEnabled,
79
77
  prefixes: [],
80
78
  ...linking,
@@ -106,21 +104,10 @@ function NavigationContainerInner(
106
104
 
107
105
  const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);
108
106
 
109
- const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
107
+ const isLinkingReady =
108
+ rest.initialState != null || !isLinkingEnabled || isResolved;
110
109
 
111
- const onReadyRef = React.useRef(onReady);
112
-
113
- React.useEffect(() => {
114
- onReadyRef.current = onReady;
115
- });
116
-
117
- React.useEffect(() => {
118
- if (isReady) {
119
- onReadyRef.current?.();
120
- }
121
- }, [isReady]);
122
-
123
- if (!isReady) {
110
+ if (!isLinkingReady) {
124
111
  // This is temporary until we have Suspense for data-fetching
125
112
  // Then the fallback will be handled by a parent `Suspense` component
126
113
  return fallback as React.ReactElement;
@@ -141,12 +128,10 @@ function NavigationContainerInner(
141
128
  );
142
129
  }
143
130
 
144
- const NavigationContainer = React.forwardRef(NavigationContainerInner) as <
145
- RootParamList extends {} = ReactNavigation.RootParamList
146
- >(
131
+ export const NavigationContainer = React.forwardRef(
132
+ NavigationContainerInner
133
+ ) as <RootParamList extends {} = ReactNavigation.RootParamList>(
147
134
  props: Props<RootParamList> & {
148
135
  ref?: React.Ref<NavigationContainerRef<RootParamList>>;
149
136
  }
150
137
  ) => React.ReactElement;
151
-
152
- export default NavigationContainer;
@@ -1,7 +1,7 @@
1
1
  import { CurrentRenderContext } from '@react-navigation/core';
2
2
  import * as React from 'react';
3
3
 
4
- import ServerContext, { ServerContextType } from './ServerContext';
4
+ import { ServerContext, ServerContextType } from './ServerContext';
5
5
  import type { ServerContainerRef } from './types';
6
6
 
7
7
  type Props = ServerContextType & {
@@ -15,7 +15,7 @@ type Props = ServerContextType & {
15
15
  * @param props.children Child elements to render the content.
16
16
  * @param props.ref Ref object which contains helper methods.
17
17
  */
18
- export default React.forwardRef(function ServerContainer(
18
+ export const ServerContainer = React.forwardRef(function ServerContainer(
19
19
  { children, location }: Props,
20
20
  ref: React.Ref<ServerContainerRef>
21
21
  ) {
@@ -7,8 +7,6 @@ export type ServerContextType = {
7
7
  };
8
8
  };
9
9
 
10
- const ServerContext = React.createContext<ServerContextType | undefined>(
10
+ export const ServerContext = React.createContext<ServerContextType | undefined>(
11
11
  undefined
12
12
  );
13
-
14
- export default ServerContext;
@@ -0,0 +1,19 @@
1
+ import {
2
+ createNavigatorFactory,
3
+ StackRouter,
4
+ useNavigationBuilder,
5
+ } from '@react-navigation/core';
6
+ import * as React from 'react';
7
+
8
+ export const createStackNavigator = createNavigatorFactory((props) => {
9
+ const { state, descriptors, NavigationContent } = useNavigationBuilder(
10
+ StackRouter,
11
+ props
12
+ );
13
+
14
+ return (
15
+ <NavigationContent>
16
+ {descriptors[state.routes[state.index].key].render()}
17
+ </NavigationContent>
18
+ );
19
+ });
@@ -63,7 +63,7 @@ const removeEventListener = (type: 'popstate', listener: () => void) => {
63
63
  }
64
64
  };
65
65
 
66
- const window = {
66
+ export const window = {
67
67
  document: { title: '' },
68
68
  location,
69
69
  history,
@@ -73,5 +73,3 @@ const window = {
73
73
  return window;
74
74
  },
75
75
  };
76
-
77
- export default window;
@@ -10,7 +10,7 @@ type HistoryRecord = {
10
10
  path: string;
11
11
  };
12
12
 
13
- export default function createMemoryHistory() {
13
+ export function createMemoryHistory() {
14
14
  let index = 0;
15
15
  let items: HistoryRecord[] = [];
16
16
 
@@ -0,0 +1,47 @@
1
+ import {
2
+ createComponentForStaticNavigation,
3
+ createPathConfigForStaticNavigation,
4
+ ParamListBase,
5
+ StaticNavigation,
6
+ } from '@react-navigation/core';
7
+ import * as React from 'react';
8
+
9
+ import { NavigationContainer } from './NavigationContainer';
10
+ import type { LinkingOptions } from './types';
11
+
12
+ type Props = Omit<
13
+ React.ComponentProps<typeof NavigationContainer>,
14
+ 'linking' | 'children'
15
+ > & {
16
+ /**
17
+ * Options for deep linking.
18
+ */
19
+ linking?: Omit<LinkingOptions<ParamListBase>, 'config'>;
20
+ };
21
+
22
+ /**
23
+ * Create a navigation component from a static navigation config.
24
+ * The returned component is a wrapper around `NavigationContainer`.
25
+ *
26
+ * @param tree Static navigation config.
27
+ * @returns Navigation component to use in your app.
28
+ */
29
+ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
30
+ const Component = createComponentForStaticNavigation(tree, 'RootNavigator');
31
+ const linkingConfig = {
32
+ screens: tree.config.screens
33
+ ? createPathConfigForStaticNavigation(tree)
34
+ : {},
35
+ };
36
+
37
+ return function Navigation({ linking, ...rest }: Props) {
38
+ return (
39
+ <NavigationContainer
40
+ {...rest}
41
+ linking={linking ? { ...linking, config: linkingConfig } : undefined}
42
+ >
43
+ <Component />
44
+ </NavigationContainer>
45
+ );
46
+ };
47
+ }
@@ -1,6 +1,6 @@
1
1
  import escapeStringRegexp from 'escape-string-regexp';
2
2
 
3
- export default function extractPathFromURL(prefixes: string[], url: string) {
3
+ export function extractPathFromURL(prefixes: string[], url: string) {
4
4
  for (const prefix of prefixes) {
5
5
  const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';
6
6
  const host = prefix
package/src/index.tsx CHANGED
@@ -1,14 +1,14 @@
1
- export { default as Link } from './Link';
2
- export { default as LinkingContext } from './LinkingContext';
3
- export { default as NavigationContainer } from './NavigationContainer';
4
- export { default as ServerContainer } from './ServerContainer';
5
- export { default as DarkTheme } from './theming/DarkTheme';
6
- export { default as DefaultTheme } from './theming/DefaultTheme';
7
- export { default as ThemeProvider } from './theming/ThemeProvider';
8
- export { default as useTheme } from './theming/useTheme';
1
+ export { createStaticNavigation } from './createStaticNavigation';
2
+ export { Link } from './Link';
3
+ export { LinkingContext } from './LinkingContext';
4
+ export { NavigationContainer } from './NavigationContainer';
5
+ export { ServerContainer } from './ServerContainer';
6
+ export { DarkTheme } from './theming/DarkTheme';
7
+ export { DefaultTheme } from './theming/DefaultTheme';
8
+ export { ThemeProvider } from './theming/ThemeProvider';
9
+ export { useTheme } from './theming/useTheme';
9
10
  export * from './types';
10
- export { default as useLinkBuilder } from './useLinkBuilder';
11
- export { default as useLinkProps } from './useLinkProps';
12
- export { default as useLinkTo } from './useLinkTo';
13
- export { default as useScrollToTop } from './useScrollToTop';
11
+ export { useLinkProps } from './useLinkProps';
12
+ export { useLinkTools } from './useLinkTools';
13
+ export { useScrollToTop } from './useScrollToTop';
14
14
  export * from '@react-navigation/core';
@@ -1,6 +1,7 @@
1
1
  import type { Theme } from '../types';
2
+ import { fonts } from './fonts';
2
3
 
3
- const DarkTheme: Theme = {
4
+ export const DarkTheme: Theme = {
4
5
  dark: true,
5
6
  colors: {
6
7
  primary: 'rgb(10, 132, 255)',
@@ -10,6 +11,5 @@ const DarkTheme: Theme = {
10
11
  border: 'rgb(39, 39, 41)',
11
12
  notification: 'rgb(255, 69, 58)',
12
13
  },
14
+ fonts,
13
15
  };
14
-
15
- export default DarkTheme;
@@ -1,6 +1,7 @@
1
1
  import type { Theme } from '../types';
2
+ import { fonts } from './fonts';
2
3
 
3
- const DefaultTheme: Theme = {
4
+ export const DefaultTheme: Theme = {
4
5
  dark: false,
5
6
  colors: {
6
7
  primary: 'rgb(0, 122, 255)',
@@ -10,6 +11,5 @@ const DefaultTheme: Theme = {
10
11
  border: 'rgb(216, 216, 216)',
11
12
  notification: 'rgb(255, 59, 48)',
12
13
  },
14
+ fonts,
13
15
  };
14
-
15
- export default DefaultTheme;
@@ -1,10 +1,8 @@
1
1
  import * as React from 'react';
2
2
 
3
3
  import type { Theme } from '../types';
4
- import DefaultTheme from './DefaultTheme';
4
+ import { DefaultTheme } from './DefaultTheme';
5
5
 
6
- const ThemeContext = React.createContext<Theme>(DefaultTheme);
6
+ export const ThemeContext = React.createContext<Theme>(DefaultTheme);
7
7
 
8
8
  ThemeContext.displayName = 'ThemeContext';
9
-
10
- export default ThemeContext;
@@ -1,14 +1,14 @@
1
1
  import * as React from 'react';
2
2
 
3
3
  import type { Theme } from '../types';
4
- import ThemeContext from './ThemeContext';
4
+ import { ThemeContext } from './ThemeContext';
5
5
 
6
6
  type Props = {
7
7
  value: Theme;
8
8
  children: React.ReactNode;
9
9
  };
10
10
 
11
- export default function ThemeProvider({ value, children }: Props) {
11
+ export function ThemeProvider({ value, children }: Props) {
12
12
  return (
13
13
  <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
14
14
  );
@@ -0,0 +1,63 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ import type { Theme } from '../types';
4
+
5
+ const WEB_FONT_STACK =
6
+ 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
7
+
8
+ export const fonts = Platform.select({
9
+ web: {
10
+ regular: {
11
+ fontFamily: WEB_FONT_STACK,
12
+ fontWeight: '400',
13
+ },
14
+ medium: {
15
+ fontFamily: WEB_FONT_STACK,
16
+ fontWeight: '500',
17
+ },
18
+ bold: {
19
+ fontFamily: WEB_FONT_STACK,
20
+ fontWeight: '600',
21
+ },
22
+ heavy: {
23
+ fontFamily: WEB_FONT_STACK,
24
+ fontWeight: '700',
25
+ },
26
+ },
27
+ ios: {
28
+ regular: {
29
+ fontFamily: 'System',
30
+ fontWeight: '400',
31
+ },
32
+ medium: {
33
+ fontFamily: 'System',
34
+ fontWeight: '500',
35
+ },
36
+ bold: {
37
+ fontFamily: 'System',
38
+ fontWeight: '600',
39
+ },
40
+ heavy: {
41
+ fontFamily: 'System',
42
+ fontWeight: '700',
43
+ },
44
+ },
45
+ default: {
46
+ regular: {
47
+ fontFamily: 'sans-serif',
48
+ fontWeight: 'normal',
49
+ },
50
+ medium: {
51
+ fontFamily: 'sans-serif-medium',
52
+ fontWeight: 'normal',
53
+ },
54
+ bold: {
55
+ fontFamily: 'sans-serif',
56
+ fontWeight: '600',
57
+ },
58
+ heavy: {
59
+ fontFamily: 'sans-serif',
60
+ fontWeight: '700',
61
+ },
62
+ },
63
+ } as const satisfies Record<string, Theme['fonts']>);
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
 
3
- import ThemeContext from './ThemeContext';
3
+ import { ThemeContext } from './ThemeContext';
4
4
 
5
- export default function useTheme() {
5
+ export function useTheme() {
6
6
  const theme = React.useContext(ThemeContext);
7
7
 
8
8
  return theme;
package/src/types.tsx CHANGED
@@ -6,6 +6,22 @@ import type {
6
6
  Route,
7
7
  } from '@react-navigation/core';
8
8
 
9
+ type FontStyle = {
10
+ fontFamily: string;
11
+ fontWeight:
12
+ | 'normal'
13
+ | 'bold'
14
+ | '100'
15
+ | '200'
16
+ | '300'
17
+ | '400'
18
+ | '500'
19
+ | '600'
20
+ | '700'
21
+ | '800'
22
+ | '900';
23
+ };
24
+
9
25
  export type Theme = {
10
26
  dark: boolean;
11
27
  colors: {
@@ -16,6 +32,12 @@ export type Theme = {
16
32
  border: string;
17
33
  notification: string;
18
34
  };
35
+ fonts: {
36
+ regular: FontStyle;
37
+ medium: FontStyle;
38
+ bold: FontStyle;
39
+ heavy: FontStyle;
40
+ };
19
41
  };
20
42
 
21
43
  export type LinkingOptions<ParamList extends {}> = {
@@ -5,7 +5,7 @@ import type {
5
5
  import * as React from 'react';
6
6
  import { BackHandler } from 'react-native';
7
7
 
8
- export default function useBackButton(
8
+ export function useBackButton(
9
9
  ref: React.RefObject<NavigationContainerRef<ParamListBase>>
10
10
  ) {
11
11
  React.useEffect(() => {
@@ -1,3 +1,3 @@
1
- export default function useDocumentTitle() {
1
+ export function useDocumentTitle() {
2
2
  // Noop for React Native
3
3
  }
@@ -9,7 +9,7 @@ import type { DocumentTitleOptions } from './types';
9
9
  /**
10
10
  * Set the document title for the active screen
11
11
  */
12
- export default function useDocumentTitle(
12
+ export function useDocumentTitle(
13
13
  ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
14
14
  {
15
15
  enabled = true,
@@ -10,16 +10,28 @@ import type { NavigationState, PartialState } from '@react-navigation/routers';
10
10
  import * as React from 'react';
11
11
  import { GestureResponderEvent, Platform } from 'react-native';
12
12
 
13
- import LinkingContext from './LinkingContext';
14
- import useLinkTo, { To } from './useLinkTo';
13
+ import { LinkingContext } from './LinkingContext';
15
14
 
16
- type Props<ParamList extends ReactNavigation.RootParamList> = {
17
- to: To<ParamList>;
18
- action?: NavigationAction;
19
- };
15
+ export type Props<
16
+ ParamList extends ReactNavigation.RootParamList,
17
+ RouteName extends keyof ParamList = keyof ParamList
18
+ > =
19
+ | ({
20
+ screen: Extract<RouteName, string>;
21
+ href?: string;
22
+ action?: NavigationAction;
23
+ } & (undefined extends ParamList[RouteName]
24
+ ? { params?: ParamList[RouteName] }
25
+ : { params: ParamList[RouteName] }))
26
+ | {
27
+ href?: string;
28
+ action: NavigationAction;
29
+ screen?: undefined;
30
+ params?: undefined;
31
+ };
20
32
 
21
33
  const getStateFromParams = (
22
- params: NavigatorScreenParams<ParamListBase, NavigationState> | undefined
34
+ params: NavigatorScreenParams<ParamListBase> | undefined
23
35
  ): PartialState<NavigationState> | NavigationState | undefined => {
24
36
  if (params?.state) {
25
37
  return params.state;
@@ -35,7 +47,7 @@ const getStateFromParams = (
35
47
  state: params.screen
36
48
  ? getStateFromParams(
37
49
  params.params as
38
- | NavigatorScreenParams<ParamListBase, NavigationState>
50
+ | NavigatorScreenParams<ParamListBase>
39
51
  | undefined
40
52
  )
41
53
  : undefined,
@@ -50,16 +62,20 @@ const getStateFromParams = (
50
62
  /**
51
63
  * Hook to get props for an anchor tag so it can work with in page navigation.
52
64
  *
53
- * @param props.to Absolute path to screen (e.g. `/feeds/hot`).
65
+ * @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
66
+ * @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
67
+ * @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
54
68
  * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
55
69
  */
56
- export default function useLinkProps<
57
- ParamList extends ReactNavigation.RootParamList
58
- >({ to, action }: Props<ParamList>) {
70
+ export function useLinkProps<ParamList extends ReactNavigation.RootParamList>({
71
+ screen,
72
+ params,
73
+ href,
74
+ action,
75
+ }: Props<ParamList>) {
59
76
  const root = React.useContext(NavigationContainerRefContext);
60
77
  const navigation = React.useContext(NavigationHelpersContext);
61
78
  const { options } = React.useContext(LinkingContext);
62
- const linkTo = useLinkTo<ParamList>();
63
79
 
64
80
  const onPress = (
65
81
  e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
@@ -93,33 +109,33 @@ export default function useLinkProps<
93
109
  );
94
110
  }
95
111
  } else {
96
- linkTo(to);
112
+ // @ts-expect-error: This is already type-checked by the prop types
113
+ navigation?.navigate(screen, params);
97
114
  }
98
115
  }
99
116
  };
100
117
 
101
118
  const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;
102
119
 
103
- const href =
104
- typeof to === 'string'
105
- ? to
106
- : getPathFromStateHelper(
107
- {
108
- routes: [
109
- {
110
- name: to.screen,
111
- // @ts-expect-error
112
- params: to.params,
113
- // @ts-expect-error
114
- state: getStateFromParams(to.params),
115
- },
116
- ],
117
- },
118
- options?.config
119
- );
120
-
121
120
  return {
122
- href,
121
+ href:
122
+ href ??
123
+ (Platform.OS === 'web' && screen != null
124
+ ? getPathFromStateHelper(
125
+ {
126
+ routes: [
127
+ {
128
+ name: screen,
129
+ // @ts-expect-error
130
+ params: params,
131
+ // @ts-expect-error
132
+ state: getStateFromParams(params),
133
+ },
134
+ ],
135
+ },
136
+ options?.config
137
+ )
138
+ : undefined),
123
139
  accessibilityRole: 'link' as const,
124
140
  onPress,
125
141
  };
@@ -1,5 +1,8 @@
1
1
  import {
2
+ CommonActions,
3
+ getActionFromState,
2
4
  getPathFromState,
5
+ getStateFromPath,
3
6
  NavigationHelpers,
4
7
  NavigationHelpersContext,
5
8
  NavigationProp,
@@ -7,7 +10,7 @@ import {
7
10
  } from '@react-navigation/core';
8
11
  import * as React from 'react';
9
12
 
10
- import LinkingContext from './LinkingContext';
13
+ import { LinkingContext } from './LinkingContext';
11
14
 
12
15
  type NavigationObject =
13
16
  | NavigationHelpers<ParamListBase>
@@ -45,11 +48,11 @@ const getRootStateForNavigate = (
45
48
  * Build destination link for a navigate action.
46
49
  * Useful for showing anchor tags on the web for buttons that perform navigation.
47
50
  */
48
- export default function useLinkBuilder() {
51
+ export function useLinkTools() {
49
52
  const navigation = React.useContext(NavigationHelpersContext);
50
53
  const linking = React.useContext(LinkingContext);
51
54
 
52
- const buildLink = React.useCallback(
55
+ const buildHref = React.useCallback(
53
56
  (name: string, params?: object) => {
54
57
  const { options } = linking;
55
58
 
@@ -78,5 +81,31 @@ export default function useLinkBuilder() {
78
81
  [linking, navigation]
79
82
  );
80
83
 
81
- return buildLink;
84
+ const buildAction = React.useCallback(
85
+ (href: string) => {
86
+ if (!href.startsWith('/')) {
87
+ throw new Error(`The path must start with '/' (${href}).`);
88
+ }
89
+
90
+ const { options } = linking;
91
+
92
+ const state = options?.getStateFromPath
93
+ ? options.getStateFromPath(href, options.config)
94
+ : getStateFromPath(href, options?.config);
95
+
96
+ if (state) {
97
+ const action = getActionFromState(state, options?.config);
98
+
99
+ return action ?? CommonActions.reset(state);
100
+ } else {
101
+ throw new Error('Failed to parse the path to a navigation state.');
102
+ }
103
+ },
104
+ [linking]
105
+ );
106
+
107
+ return {
108
+ buildHref,
109
+ buildAction,
110
+ };
82
111
  }