@react-navigation/native 7.0.0-rc.17 → 7.0.0-rc.19

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.
@@ -51,19 +51,46 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
51
51
  { linking, ...rest }: Props,
52
52
  ref: React.Ref<NavigationContainerRef<ParamListBase>>
53
53
  ) {
54
- const screens = React.useMemo(() => {
55
- if (tree.config.screens) {
56
- return createPathConfigForStaticNavigation(
57
- tree,
58
- { initialRouteName: linking?.config?.initialRouteName },
59
- linking?.enabled === 'auto'
60
- );
54
+ const linkingConfig = React.useMemo(() => {
55
+ if (!tree.config.screens) return;
56
+
57
+ const screens = createPathConfigForStaticNavigation(
58
+ tree,
59
+ { initialRouteName: linking?.config?.initialRouteName },
60
+ linking?.enabled === 'auto'
61
+ );
62
+
63
+ if (!screens) return;
64
+
65
+ return {
66
+ path: linking?.config?.path,
67
+ initialRouteName: linking?.config?.initialRouteName,
68
+ screens,
69
+ };
70
+ }, [
71
+ linking?.enabled,
72
+ linking?.config?.path,
73
+ linking?.config?.initialRouteName,
74
+ ]);
75
+
76
+ const memoizedLinking = React.useMemo(() => {
77
+ if (!linking) {
78
+ return undefined;
61
79
  }
62
80
 
63
- return undefined;
64
- }, [linking?.config, linking?.enabled]);
81
+ const enabled =
82
+ typeof linking.enabled === 'boolean'
83
+ ? linking.enabled
84
+ : linkingConfig?.screens != null;
85
+
86
+ return {
87
+ ...linking,
88
+ enabled,
89
+ config: linkingConfig,
90
+ };
91
+ }, [linking, linkingConfig]);
65
92
 
66
- if (linking?.enabled === true && screens == null) {
93
+ if (linking?.enabled === true && linkingConfig?.screens == null) {
67
94
  throw new Error(
68
95
  'Linking is enabled but no linking configuration was found for the screens.\n\n' +
69
96
  'To solve this:\n' +
@@ -74,22 +101,7 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
74
101
  }
75
102
 
76
103
  return (
77
- <NavigationContainer
78
- {...rest}
79
- ref={ref}
80
- linking={
81
- linking
82
- ? {
83
- ...linking,
84
- enabled:
85
- typeof linking.enabled === 'boolean'
86
- ? linking.enabled
87
- : screens != null,
88
- config: screens ? { ...linking.config, screens } : undefined,
89
- }
90
- : undefined
91
- }
92
- >
104
+ <NavigationContainer {...rest} ref={ref} linking={memoizedLinking}>
93
105
  <Component />
94
106
  </NavigationContainer>
95
107
  );
@@ -19,11 +19,11 @@ export type LinkProps<
19
19
  | ({
20
20
  href?: string;
21
21
  action?: NavigationAction;
22
- } & (RouteName extends unknown // Similar conditional to navigation.navigate
23
- ? undefined extends ParamList[RouteName]
24
- ? { screen: RouteName; params?: ParamList[RouteName] }
25
- : { screen: RouteName; params: ParamList[RouteName] }
26
- : never))
22
+ } & {
23
+ [Screen in keyof ParamList]: undefined extends ParamList[Screen]
24
+ ? { screen: Screen; params?: ParamList[Screen] }
25
+ : { screen: Screen; params: ParamList[Screen] };
26
+ }[RouteName])
27
27
  | {
28
28
  href?: string;
29
29
  action: NavigationAction;