@react-navigation/native 8.0.0-alpha.0 → 8.0.0-alpha.10

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 (128) hide show
  1. package/ReactNavigation.podspec +20 -0
  2. package/android/build.gradle +147 -0
  3. package/android/src/main/AndroidManifest.xml +2 -0
  4. package/android/src/main/java/org/reactnavigation/MaterialSymbolModule.kt +100 -0
  5. package/android/src/main/java/org/reactnavigation/MaterialSymbolTypeface.kt +77 -0
  6. package/android/src/main/java/org/reactnavigation/MaterialSymbolView.kt +95 -0
  7. package/android/src/main/java/org/reactnavigation/MaterialSymbolViewManager.kt +49 -0
  8. package/android/src/main/java/org/reactnavigation/ReactNavigationPackage.kt +34 -0
  9. package/assets/fonts/MaterialSymbolsOutlined.codepoints +4102 -0
  10. package/assets/fonts/MaterialSymbolsOutlined_100.ttf +0 -0
  11. package/assets/fonts/MaterialSymbolsOutlined_200.ttf +0 -0
  12. package/assets/fonts/MaterialSymbolsOutlined_300.ttf +0 -0
  13. package/assets/fonts/MaterialSymbolsOutlined_400.ttf +0 -0
  14. package/assets/fonts/MaterialSymbolsOutlined_500.ttf +0 -0
  15. package/assets/fonts/MaterialSymbolsOutlined_600.ttf +0 -0
  16. package/assets/fonts/MaterialSymbolsOutlined_700.ttf +0 -0
  17. package/assets/fonts/MaterialSymbolsRounded.codepoints +4102 -0
  18. package/assets/fonts/MaterialSymbolsRounded_100.ttf +0 -0
  19. package/assets/fonts/MaterialSymbolsRounded_200.ttf +0 -0
  20. package/assets/fonts/MaterialSymbolsRounded_300.ttf +0 -0
  21. package/assets/fonts/MaterialSymbolsRounded_400.ttf +0 -0
  22. package/assets/fonts/MaterialSymbolsRounded_500.ttf +0 -0
  23. package/assets/fonts/MaterialSymbolsRounded_600.ttf +0 -0
  24. package/assets/fonts/MaterialSymbolsRounded_700.ttf +0 -0
  25. package/assets/fonts/MaterialSymbolsSharp.codepoints +4102 -0
  26. package/assets/fonts/MaterialSymbolsSharp_100.ttf +0 -0
  27. package/assets/fonts/MaterialSymbolsSharp_200.ttf +0 -0
  28. package/assets/fonts/MaterialSymbolsSharp_300.ttf +0 -0
  29. package/assets/fonts/MaterialSymbolsSharp_400.ttf +0 -0
  30. package/assets/fonts/MaterialSymbolsSharp_500.ttf +0 -0
  31. package/assets/fonts/MaterialSymbolsSharp_600.ttf +0 -0
  32. package/assets/fonts/MaterialSymbolsSharp_700.ttf +0 -0
  33. package/ios/ReactNavigationSFSymbolView.h +14 -0
  34. package/ios/ReactNavigationSFSymbolView.mm +79 -0
  35. package/ios/ReactNavigationSFSymbolView.swift +300 -0
  36. package/lib/module/NavigationContainer.js +7 -2
  37. package/lib/module/NavigationContainer.js.map +1 -1
  38. package/lib/module/createStaticNavigation.js +3 -6
  39. package/lib/module/createStaticNavigation.js.map +1 -1
  40. package/lib/module/index.js +4 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/native/MaterialSymbol.android.js +58 -0
  43. package/lib/module/native/MaterialSymbol.android.js.map +1 -0
  44. package/lib/module/native/MaterialSymbol.js +9 -0
  45. package/lib/module/native/MaterialSymbol.js.map +1 -0
  46. package/lib/module/native/MaterialSymbolData.js +2 -0
  47. package/lib/module/native/MaterialSymbolData.js.map +1 -0
  48. package/lib/module/native/MaterialSymbolViewNativeComponent.ts +23 -0
  49. package/lib/module/native/NativeMaterialSymbolModule.js +7 -0
  50. package/lib/module/native/NativeMaterialSymbolModule.js.map +1 -0
  51. package/lib/module/native/SFSymbol.ios.js +46 -0
  52. package/lib/module/native/SFSymbol.ios.js.map +1 -0
  53. package/lib/module/native/SFSymbol.js +6 -0
  54. package/lib/module/native/SFSymbol.js.map +1 -0
  55. package/lib/module/native/SFSymbolViewNativeComponent.ts +32 -0
  56. package/lib/module/native/constants.js +14 -0
  57. package/lib/module/native/constants.js.map +1 -0
  58. package/lib/module/native/types.js +4 -0
  59. package/lib/module/native/types.js.map +1 -0
  60. package/lib/module/theming/{DefaultTheme.js → LightTheme.js} +2 -2
  61. package/lib/module/theming/LightTheme.js.map +1 -0
  62. package/lib/module/theming/MaterialTheme.android.js +29 -0
  63. package/lib/module/theming/MaterialTheme.android.js.map +1 -0
  64. package/lib/module/theming/MaterialTheme.js +18 -0
  65. package/lib/module/theming/MaterialTheme.js.map +1 -0
  66. package/lib/module/useLinkBuilder.js +24 -5
  67. package/lib/module/useLinkBuilder.js.map +1 -1
  68. package/lib/module/useLinkTo.js +2 -4
  69. package/lib/module/useLinkTo.js.map +1 -1
  70. package/lib/module/useLinking.native.js +20 -3
  71. package/lib/module/useLinking.native.js.map +1 -1
  72. package/lib/typescript/src/NavigationContainer.d.ts +6 -1
  73. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -1
  74. package/lib/typescript/src/createStaticNavigation.d.ts +3 -3
  75. package/lib/typescript/src/createStaticNavigation.d.ts.map +1 -1
  76. package/lib/typescript/src/index.d.ts +4 -1
  77. package/lib/typescript/src/index.d.ts.map +1 -1
  78. package/lib/typescript/src/native/MaterialSymbol.android.d.ts +8 -0
  79. package/lib/typescript/src/native/MaterialSymbol.android.d.ts.map +1 -0
  80. package/lib/typescript/src/native/MaterialSymbol.d.ts +8 -0
  81. package/lib/typescript/src/native/MaterialSymbol.d.ts.map +1 -0
  82. package/lib/typescript/src/native/MaterialSymbolData.d.ts +2 -0
  83. package/lib/typescript/src/native/MaterialSymbolData.d.ts.map +1 -0
  84. package/lib/typescript/src/native/MaterialSymbolViewNativeComponent.d.ts +11 -0
  85. package/lib/typescript/src/native/MaterialSymbolViewNativeComponent.d.ts.map +1 -0
  86. package/lib/typescript/src/native/NativeMaterialSymbolModule.d.ts +7 -0
  87. package/lib/typescript/src/native/NativeMaterialSymbolModule.d.ts.map +1 -0
  88. package/lib/typescript/src/native/SFSymbol.d.ts +5 -0
  89. package/lib/typescript/src/native/SFSymbol.d.ts.map +1 -0
  90. package/lib/typescript/src/native/SFSymbol.ios.d.ts +5 -0
  91. package/lib/typescript/src/native/SFSymbol.ios.d.ts.map +1 -0
  92. package/lib/typescript/src/native/SFSymbolViewNativeComponent.d.ts +23 -0
  93. package/lib/typescript/src/native/SFSymbolViewNativeComponent.d.ts.map +1 -0
  94. package/lib/typescript/src/native/constants.d.ts +12 -0
  95. package/lib/typescript/src/native/constants.d.ts.map +1 -0
  96. package/lib/typescript/src/native/types.d.ts +181 -0
  97. package/lib/typescript/src/native/types.d.ts.map +1 -0
  98. package/lib/typescript/src/theming/{DefaultTheme.d.ts → LightTheme.d.ts} +2 -2
  99. package/lib/typescript/src/theming/LightTheme.d.ts.map +1 -0
  100. package/lib/typescript/src/theming/MaterialTheme.android.d.ts +127 -0
  101. package/lib/typescript/src/theming/MaterialTheme.android.d.ts.map +1 -0
  102. package/lib/typescript/src/theming/MaterialTheme.d.ts +114 -0
  103. package/lib/typescript/src/theming/MaterialTheme.d.ts.map +1 -0
  104. package/lib/typescript/src/useLinkBuilder.d.ts +104 -6
  105. package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -1
  106. package/lib/typescript/src/useLinking.native.d.ts.map +1 -1
  107. package/package.json +39 -4
  108. package/src/NavigationContainer.tsx +20 -3
  109. package/src/createStaticNavigation.tsx +8 -12
  110. package/src/index.tsx +7 -1
  111. package/src/native/MaterialSymbol.android.tsx +83 -0
  112. package/src/native/MaterialSymbol.tsx +17 -0
  113. package/src/native/MaterialSymbolData.tsx +4106 -0
  114. package/src/native/MaterialSymbolViewNativeComponent.ts +23 -0
  115. package/src/native/NativeMaterialSymbolModule.ts +19 -0
  116. package/src/native/SFSymbol.ios.tsx +53 -0
  117. package/src/native/SFSymbol.tsx +9 -0
  118. package/src/native/SFSymbolViewNativeComponent.ts +32 -0
  119. package/src/native/constants.tsx +11 -0
  120. package/src/native/types.tsx +218 -0
  121. package/src/theming/{DefaultTheme.tsx → LightTheme.tsx} +1 -1
  122. package/src/theming/MaterialTheme.android.tsx +30 -0
  123. package/src/theming/MaterialTheme.tsx +19 -0
  124. package/src/useLinkBuilder.tsx +26 -6
  125. package/src/useLinkTo.tsx +2 -2
  126. package/src/useLinking.native.tsx +38 -15
  127. package/lib/module/theming/DefaultTheme.js.map +0 -1
  128. package/lib/typescript/src/theming/DefaultTheme.d.ts.map +0 -1
@@ -6,7 +6,9 @@ import {
6
6
  type InitialState,
7
7
  type NavigationContainerProps,
8
8
  type NavigationContainerRef,
9
+ type NavigationState,
9
10
  type ParamListBase,
11
+ type PartialState,
10
12
  type RootParamList,
11
13
  ThemeProvider,
12
14
  validatePathConfig,
@@ -16,7 +18,7 @@ import { I18nManager, Platform } from 'react-native';
16
18
 
17
19
  import { LinkingContext } from './LinkingContext';
18
20
  import { LocaleDirContext } from './LocaleDirContext';
19
- import { DefaultTheme } from './theming/DefaultTheme';
21
+ import { LightTheme } from './theming/LightTheme';
20
22
  import type {
21
23
  DocumentTitleOptions,
22
24
  LinkingOptions,
@@ -31,7 +33,16 @@ import { type Thenable, useThenable } from './useThenable';
31
33
  declare global {
32
34
  var REACT_NAVIGATION_DEVTOOLS: WeakMap<
33
35
  NavigationContainerRef<any>,
34
- { readonly linking: LinkingOptions<any> }
36
+ {
37
+ readonly linking: LinkingOptions<any>;
38
+ readonly listeners: Set<
39
+ (data: {
40
+ type: 'link';
41
+ url: string;
42
+ state: PartialState<NavigationState> | undefined;
43
+ }) => void
44
+ >;
45
+ }
35
46
  >;
36
47
  }
37
48
 
@@ -103,7 +114,7 @@ const RESTORE_STATE_ERROR =
103
114
  function NavigationContainerInner(
104
115
  {
105
116
  direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
106
- theme = DefaultTheme,
117
+ theme = LightTheme,
107
118
  linking,
108
119
  persistor,
109
120
  fallback = null,
@@ -150,10 +161,16 @@ function NavigationContainerInner(
150
161
  // This will be used by the devtools
151
162
  React.useEffect(() => {
152
163
  if (refContainer.current) {
164
+ const previous = REACT_NAVIGATION_DEVTOOLS.get(refContainer.current);
165
+ const listeners = previous?.listeners ?? new Set();
166
+
153
167
  REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
154
168
  get linking() {
155
169
  return linkingConfig.options;
156
170
  },
171
+ get listeners() {
172
+ return listeners;
173
+ },
157
174
  });
158
175
  }
159
176
  });
@@ -20,10 +20,10 @@ type Props = Omit<
20
20
  linking?: Omit<LinkingOptions<ParamListBase>, 'config' | 'enabled'> & {
21
21
  /**
22
22
  * Whether deep link handling should be enabled.
23
- * Defaults to `true` if any `linking` options are specified, `false` otherwise.
23
+ * Defaults to `auto`.
24
24
  *
25
- * When 'auto' is specified, all leaf screens will get a autogenerated path.
26
- * The generated path will be a kebab-case version of the screen name.
25
+ * When set to 'auto', all leaf screens will get autogenerated paths.
26
+ * The generated paths will be kebab-case versions of the screen names.
27
27
  * This can be overridden for specific screens by specifying `linking` for the screen.
28
28
  */
29
29
  enabled?: 'auto' | true | false;
@@ -55,7 +55,7 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
55
55
  const screens = createPathConfigForStaticNavigation(
56
56
  tree,
57
57
  { initialRouteName: linking?.config?.initialRouteName },
58
- linking?.enabled === 'auto'
58
+ linking?.enabled == null || linking.enabled === 'auto'
59
59
  );
60
60
 
61
61
  if (!screens) return;
@@ -72,14 +72,10 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
72
72
  ]);
73
73
 
74
74
  const memoizedLinking = React.useMemo(() => {
75
- if (!linking) {
76
- return undefined;
77
- }
78
-
79
75
  const enabled =
80
- typeof linking.enabled === 'boolean'
81
- ? linking.enabled
82
- : linkingConfig?.screens != null;
76
+ linking?.enabled == null || linking.enabled === 'auto'
77
+ ? true
78
+ : linking.enabled;
83
79
 
84
80
  return {
85
81
  ...linking,
@@ -92,7 +88,7 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
92
88
  throw new Error(
93
89
  'Linking is enabled but no linking configuration was found for the screens.\n\n' +
94
90
  'To solve this:\n' +
95
- "- Specify a 'linking' property for the screens you want to link to.\n" +
91
+ "- Specify a 'linking' property in each of the screen configs that you want to link to.\n" +
96
92
  "- Or set 'linking.enabled' to 'auto' to generate paths automatically.\n\n" +
97
93
  'See usage guide: https://reactnavigation.org/docs/static-configuration#linking'
98
94
  );
package/src/index.tsx CHANGED
@@ -2,10 +2,16 @@ export { createStaticNavigation } from './createStaticNavigation';
2
2
  export { Link } from './Link';
3
3
  export { LinkingContext } from './LinkingContext';
4
4
  export { LocaleDirContext } from './LocaleDirContext';
5
+ export {
6
+ MaterialSymbol,
7
+ type MaterialSymbolProps,
8
+ } from './native/MaterialSymbol';
9
+ export { SFSymbol, type SFSymbolProps } from './native/SFSymbol';
5
10
  export { NavigationContainer } from './NavigationContainer';
6
11
  export { ServerContainer } from './ServerContainer';
7
12
  export { DarkTheme } from './theming/DarkTheme';
8
- export { DefaultTheme } from './theming/DefaultTheme';
13
+ export { LightTheme as DefaultTheme } from './theming/LightTheme';
14
+ export { MaterialDarkTheme, MaterialLightTheme } from './theming/MaterialTheme';
9
15
  export * from './types';
10
16
  export { useLinkBuilder } from './useLinkBuilder';
11
17
  export { type LinkProps, useLinkProps } from './useLinkProps';
@@ -0,0 +1,83 @@
1
+ import {
2
+ type ImageSourcePropType,
3
+ PixelRatio,
4
+ processColor,
5
+ type ViewProps,
6
+ } from 'react-native';
7
+
8
+ import { FONT_WEIGHTS } from './constants';
9
+ import MaterialSymbolViewNativeComponent from './MaterialSymbolViewNativeComponent';
10
+ import NativeMaterialSymbolModule from './NativeMaterialSymbolModule';
11
+ import type { MaterialSymbolOptions } from './types';
12
+
13
+ export type MaterialSymbolProps = MaterialSymbolOptions & ViewProps;
14
+
15
+ const imageSourceCache = new Map<string, ImageSourcePropType>();
16
+
17
+ export function MaterialSymbol({
18
+ name,
19
+ weight,
20
+ size = 24,
21
+ color,
22
+ style,
23
+ ...rest
24
+ }: MaterialSymbolProps): React.ReactElement {
25
+ return (
26
+ <MaterialSymbolViewNativeComponent
27
+ name={name}
28
+ weight={typeof weight === 'string' ? FONT_WEIGHTS[weight] : (weight ?? 0)}
29
+ size={size}
30
+ color={color}
31
+ style={[
32
+ {
33
+ width: size,
34
+ height: size,
35
+ },
36
+ style,
37
+ ]}
38
+ {...rest}
39
+ />
40
+ );
41
+ }
42
+
43
+ MaterialSymbol.getImageSource = ({
44
+ name,
45
+ variant,
46
+ weight,
47
+ size = 24,
48
+ color = 'black',
49
+ }: MaterialSymbolOptions): ImageSourcePropType => {
50
+ const processedColor = processColor(color);
51
+
52
+ if (processedColor == null) {
53
+ throw new Error(`Invalid color value: ${String(color)}`);
54
+ }
55
+
56
+ const scale = PixelRatio.get();
57
+
58
+ const cacheKey = `${name}:${variant}:${weight}:${size}:${scale}:${JSON.stringify(processedColor)}`;
59
+ const cached = imageSourceCache.get(cacheKey);
60
+
61
+ if (cached !== undefined) {
62
+ return cached;
63
+ }
64
+
65
+ const uri = NativeMaterialSymbolModule.getImageSource(
66
+ name,
67
+ variant,
68
+ typeof weight === 'string' ? FONT_WEIGHTS[weight] : weight,
69
+ size,
70
+ { value: processedColor }
71
+ );
72
+
73
+ const source: ImageSourcePropType = {
74
+ uri,
75
+ scale,
76
+ width: size,
77
+ height: size,
78
+ };
79
+
80
+ imageSourceCache.set(cacheKey, source);
81
+
82
+ return source;
83
+ };
@@ -0,0 +1,17 @@
1
+ import { type ImageSourcePropType, type ViewProps } from 'react-native';
2
+
3
+ import type { MaterialSymbolOptions } from './types';
4
+
5
+ export type MaterialSymbolProps = MaterialSymbolOptions & ViewProps;
6
+
7
+ export function MaterialSymbol(_: MaterialSymbolProps): React.ReactElement {
8
+ throw new Error('MaterialSymbol is only supported on Android.');
9
+ }
10
+
11
+ MaterialSymbol.getImageSource = (
12
+ _: MaterialSymbolOptions
13
+ ): ImageSourcePropType => {
14
+ throw new Error(
15
+ 'MaterialSymbol.getImageSource is only supported on Android.'
16
+ );
17
+ };