react-native-screens 3.18.1 → 3.19.0

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 (154) hide show
  1. package/README.md +30 -38
  2. package/android/build.gradle +1 -5
  3. package/android/src/main/java/com/swmansion/rnscreens/ScreenViewManager.kt +10 -0
  4. package/android/src/paper/java/com/facebook/react/viewmanagers/RNSScreenManagerDelegate.java +15 -0
  5. package/android/src/paper/java/com/facebook/react/viewmanagers/RNSScreenManagerInterface.java +5 -0
  6. package/ios/RNSConvert.h +6 -0
  7. package/ios/RNSConvert.mm +26 -0
  8. package/ios/RNSEnums.h +6 -0
  9. package/ios/RNSFullWindowOverlay.mm +32 -0
  10. package/ios/RNSScreen.h +10 -2
  11. package/ios/RNSScreen.mm +133 -2
  12. package/ios/RNSScreenStackHeaderConfig.mm +17 -1
  13. package/lib/commonjs/TransitionProgressContext.js +2 -7
  14. package/lib/commonjs/TransitionProgressContext.js.map +1 -1
  15. package/lib/commonjs/createNativeStackNavigator.js +29 -76
  16. package/lib/commonjs/createNativeStackNavigator.js.map +1 -1
  17. package/lib/commonjs/fabric/FullWindowOverlayNativeComponent.js +0 -5
  18. package/lib/commonjs/fabric/FullWindowOverlayNativeComponent.js.map +1 -1
  19. package/lib/commonjs/fabric/ScreenContainerNativeComponent.js +0 -5
  20. package/lib/commonjs/fabric/ScreenContainerNativeComponent.js.map +1 -1
  21. package/lib/commonjs/fabric/ScreenNativeComponent.js +0 -5
  22. package/lib/commonjs/fabric/ScreenNativeComponent.js.map +1 -1
  23. package/lib/commonjs/fabric/ScreenNavigationContainerNativeComponent.js +0 -5
  24. package/lib/commonjs/fabric/ScreenNavigationContainerNativeComponent.js.map +1 -1
  25. package/lib/commonjs/fabric/ScreenStackHeaderConfigNativeComponent.js +2 -10
  26. package/lib/commonjs/fabric/ScreenStackHeaderConfigNativeComponent.js.map +1 -1
  27. package/lib/commonjs/fabric/ScreenStackHeaderSubviewNativeComponent.js +2 -10
  28. package/lib/commonjs/fabric/ScreenStackHeaderSubviewNativeComponent.js.map +1 -1
  29. package/lib/commonjs/fabric/ScreenStackNativeComponent.js +0 -5
  30. package/lib/commonjs/fabric/ScreenStackNativeComponent.js.map +1 -1
  31. package/lib/commonjs/fabric/SearchBarNativeComponent.js +0 -7
  32. package/lib/commonjs/fabric/SearchBarNativeComponent.js.map +1 -1
  33. package/lib/commonjs/index.js +21 -45
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/index.native.js +43 -103
  36. package/lib/commonjs/index.native.js.map +1 -1
  37. package/lib/commonjs/native-stack/index.js +6 -11
  38. package/lib/commonjs/native-stack/index.js.map +1 -1
  39. package/lib/commonjs/native-stack/navigators/createNativeStackNavigator.js +18 -25
  40. package/lib/commonjs/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
  41. package/lib/commonjs/native-stack/types.js +4 -0
  42. package/lib/commonjs/native-stack/types.js.map +1 -1
  43. package/lib/commonjs/native-stack/utils/HeaderHeightContext.js +2 -6
  44. package/lib/commonjs/native-stack/utils/HeaderHeightContext.js.map +1 -1
  45. package/lib/commonjs/native-stack/utils/SafeAreaProviderCompat.js +11 -19
  46. package/lib/commonjs/native-stack/utils/SafeAreaProviderCompat.js.map +1 -1
  47. package/lib/commonjs/native-stack/utils/getDefaultHeaderHeight.js +0 -7
  48. package/lib/commonjs/native-stack/utils/getDefaultHeaderHeight.js.map +1 -1
  49. package/lib/commonjs/native-stack/utils/useBackPressSubscription.js +7 -18
  50. package/lib/commonjs/native-stack/utils/useBackPressSubscription.js.map +1 -1
  51. package/lib/commonjs/native-stack/utils/useHeaderHeight.js +2 -10
  52. package/lib/commonjs/native-stack/utils/useHeaderHeight.js.map +1 -1
  53. package/lib/commonjs/native-stack/views/FontProcessor.js +1 -6
  54. package/lib/commonjs/native-stack/views/FontProcessor.js.map +1 -1
  55. package/lib/commonjs/native-stack/views/HeaderConfig.js +46 -50
  56. package/lib/commonjs/native-stack/views/HeaderConfig.js.map +1 -1
  57. package/lib/commonjs/native-stack/views/NativeStackView.js +32 -58
  58. package/lib/commonjs/native-stack/views/NativeStackView.js.map +1 -1
  59. package/lib/commonjs/reanimated/ReanimatedNativeStackScreen.js +11 -21
  60. package/lib/commonjs/reanimated/ReanimatedNativeStackScreen.js.map +1 -1
  61. package/lib/commonjs/reanimated/ReanimatedScreen.js +3 -10
  62. package/lib/commonjs/reanimated/ReanimatedScreen.js.map +1 -1
  63. package/lib/commonjs/reanimated/ReanimatedScreenProvider.js +3 -19
  64. package/lib/commonjs/reanimated/ReanimatedScreenProvider.js.map +1 -1
  65. package/lib/commonjs/reanimated/ReanimatedTransitionProgressContext.js +2 -7
  66. package/lib/commonjs/reanimated/ReanimatedTransitionProgressContext.js.map +1 -1
  67. package/lib/commonjs/reanimated/index.js +0 -3
  68. package/lib/commonjs/reanimated/index.js.map +1 -1
  69. package/lib/commonjs/reanimated/useReanimatedTransitionProgress.js +2 -10
  70. package/lib/commonjs/reanimated/useReanimatedTransitionProgress.js.map +1 -1
  71. package/lib/commonjs/types.js +4 -0
  72. package/lib/commonjs/types.js.map +1 -1
  73. package/lib/commonjs/useTransitionProgress.js +2 -10
  74. package/lib/commonjs/useTransitionProgress.js.map +1 -1
  75. package/lib/commonjs/utils.js +0 -4
  76. package/lib/commonjs/utils.js.map +1 -1
  77. package/lib/module/TransitionProgressContext.js.map +1 -1
  78. package/lib/module/createNativeStackNavigator.js +29 -67
  79. package/lib/module/createNativeStackNavigator.js.map +1 -1
  80. package/lib/module/fabric/FullWindowOverlayNativeComponent.js +0 -1
  81. package/lib/module/fabric/FullWindowOverlayNativeComponent.js.map +1 -1
  82. package/lib/module/fabric/ScreenContainerNativeComponent.js +0 -1
  83. package/lib/module/fabric/ScreenContainerNativeComponent.js.map +1 -1
  84. package/lib/module/fabric/ScreenNativeComponent.js +0 -1
  85. package/lib/module/fabric/ScreenNativeComponent.js.map +1 -1
  86. package/lib/module/fabric/ScreenNavigationContainerNativeComponent.js +0 -1
  87. package/lib/module/fabric/ScreenNavigationContainerNativeComponent.js.map +1 -1
  88. package/lib/module/fabric/ScreenStackHeaderConfigNativeComponent.js +0 -1
  89. package/lib/module/fabric/ScreenStackHeaderConfigNativeComponent.js.map +1 -1
  90. package/lib/module/fabric/ScreenStackHeaderSubviewNativeComponent.js +0 -1
  91. package/lib/module/fabric/ScreenStackHeaderSubviewNativeComponent.js.map +1 -1
  92. package/lib/module/fabric/ScreenStackNativeComponent.js +0 -1
  93. package/lib/module/fabric/ScreenStackNativeComponent.js.map +1 -1
  94. package/lib/module/fabric/SearchBarNativeComponent.js +0 -1
  95. package/lib/module/fabric/SearchBarNativeComponent.js.map +1 -1
  96. package/lib/module/index.js +13 -11
  97. package/lib/module/index.js.map +1 -1
  98. package/lib/module/index.native.js +45 -93
  99. package/lib/module/index.native.js.map +1 -1
  100. package/lib/module/native-stack/index.js +3 -2
  101. package/lib/module/native-stack/index.js.map +1 -1
  102. package/lib/module/native-stack/navigators/createNativeStackNavigator.js +16 -16
  103. package/lib/module/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
  104. package/lib/module/native-stack/types.js +1 -1
  105. package/lib/module/native-stack/types.js.map +1 -1
  106. package/lib/module/native-stack/utils/HeaderHeightContext.js.map +1 -1
  107. package/lib/module/native-stack/utils/SafeAreaProviderCompat.js +8 -7
  108. package/lib/module/native-stack/utils/SafeAreaProviderCompat.js.map +1 -1
  109. package/lib/module/native-stack/utils/getDefaultHeaderHeight.js +0 -4
  110. package/lib/module/native-stack/utils/getDefaultHeaderHeight.js.map +1 -1
  111. package/lib/module/native-stack/utils/useBackPressSubscription.js +7 -8
  112. package/lib/module/native-stack/utils/useBackPressSubscription.js.map +1 -1
  113. package/lib/module/native-stack/utils/useHeaderHeight.js +0 -2
  114. package/lib/module/native-stack/utils/useHeaderHeight.js.map +1 -1
  115. package/lib/module/native-stack/views/FontProcessor.js +0 -3
  116. package/lib/module/native-stack/views/FontProcessor.js.map +1 -1
  117. package/lib/module/native-stack/views/HeaderConfig.js +44 -39
  118. package/lib/module/native-stack/views/HeaderConfig.js.map +1 -1
  119. package/lib/module/native-stack/views/NativeStackView.js +32 -42
  120. package/lib/module/native-stack/views/NativeStackView.js.map +1 -1
  121. package/lib/module/reanimated/ReanimatedNativeStackScreen.js +12 -9
  122. package/lib/module/reanimated/ReanimatedNativeStackScreen.js.map +1 -1
  123. package/lib/module/reanimated/ReanimatedScreen.js +5 -4
  124. package/lib/module/reanimated/ReanimatedScreen.js.map +1 -1
  125. package/lib/module/reanimated/ReanimatedScreenProvider.js +3 -14
  126. package/lib/module/reanimated/ReanimatedScreenProvider.js.map +1 -1
  127. package/lib/module/reanimated/ReanimatedTransitionProgressContext.js +2 -1
  128. package/lib/module/reanimated/ReanimatedTransitionProgressContext.js.map +1 -1
  129. package/lib/module/reanimated/index.js.map +1 -1
  130. package/lib/module/reanimated/useReanimatedTransitionProgress.js +0 -2
  131. package/lib/module/reanimated/useReanimatedTransitionProgress.js.map +1 -1
  132. package/lib/module/types.js +1 -1
  133. package/lib/module/types.js.map +1 -1
  134. package/lib/module/useTransitionProgress.js +0 -2
  135. package/lib/module/useTransitionProgress.js.map +1 -1
  136. package/lib/module/utils.js.map +1 -1
  137. package/lib/typescript/index.d.ts +4 -2
  138. package/lib/typescript/native-stack/navigators/createNativeStackNavigator.d.ts +1 -0
  139. package/lib/typescript/native-stack/views/HeaderConfig.d.ts +1 -0
  140. package/lib/typescript/native-stack/views/NativeStackView.d.ts +1 -0
  141. package/lib/typescript/reanimated/ReanimatedNativeStackScreen.d.ts +1 -1
  142. package/lib/typescript/reanimated/ReanimatedScreen.d.ts +1 -1
  143. package/lib/typescript/types.d.ts +1 -0
  144. package/package.json +9 -1
  145. package/react-native.config.js +12 -2
  146. package/src/createNativeStackNavigator.tsx +4 -2
  147. package/src/fabric/ScreenNativeComponent.js +7 -0
  148. package/src/index.native.tsx +32 -16
  149. package/src/index.tsx +13 -8
  150. package/src/native-stack/types.tsx +4 -5
  151. package/src/native-stack/views/HeaderConfig.tsx +8 -10
  152. package/src/native-stack/views/NativeStackView.tsx +8 -4
  153. package/src/reanimated/ReanimatedNativeStackScreen.tsx +5 -3
  154. package/src/reanimated/ReanimatedScreen.tsx +1 -1
@@ -1,14 +1,16 @@
1
- import React from 'react';
1
+ import React, { PropsWithChildren, ReactNode } from 'react';
2
2
  import {
3
3
  Animated,
4
4
  Image,
5
5
  ImageProps,
6
6
  Platform,
7
7
  requireNativeComponent,
8
+ StyleProp,
8
9
  StyleSheet,
9
10
  UIManager,
10
11
  View,
11
12
  ViewProps,
13
+ ViewStyle,
12
14
  } from 'react-native';
13
15
  import { Freeze } from 'react-freeze';
14
16
  import { version } from 'react-native/package.json';
@@ -79,12 +81,16 @@ let NativeScreenContainerValue: React.ComponentType<ScreenContainerProps>;
79
81
  let NativeScreenNavigationContainerValue: React.ComponentType<ScreenContainerProps>;
80
82
  let NativeScreenStack: React.ComponentType<ScreenStackProps>;
81
83
  let NativeScreenStackHeaderConfig: React.ComponentType<ScreenStackHeaderConfigProps>;
82
- let NativeScreenStackHeaderSubview: React.ComponentType<React.PropsWithChildren<
83
- ViewProps & { type?: HeaderSubviewTypes }
84
- >>;
84
+ let NativeScreenStackHeaderSubview: React.ComponentType<
85
+ React.PropsWithChildren<ViewProps & { type?: HeaderSubviewTypes }>
86
+ >;
85
87
  let AnimatedNativeScreen: React.ComponentType<ScreenProps>;
86
88
  let NativeSearchBar: React.ComponentType<SearchBarProps>;
87
- let NativeFullWindowOverlay: React.ComponentType<View>;
89
+ let NativeFullWindowOverlay: React.ComponentType<
90
+ PropsWithChildren<{
91
+ style: StyleProp<ViewStyle>;
92
+ }>
93
+ >;
88
94
 
89
95
  const ScreensNativeModules = {
90
96
  get NativeScreen() {
@@ -284,7 +290,8 @@ class InnerScreen extends React.Component<ScreenProps> {
284
290
  ],
285
291
  { useNativeDriver: true }
286
292
  )
287
- }>
293
+ }
294
+ >
288
295
  {!isNativeStack ? ( // see comment of this prop in types.tsx for information why it is needed
289
296
  children
290
297
  ) : (
@@ -293,7 +300,8 @@ class InnerScreen extends React.Component<ScreenProps> {
293
300
  progress: this.progress,
294
301
  closing: this.closing,
295
302
  goingForward: this.goingForward,
296
- }}>
303
+ }}
304
+ >
297
305
  {children}
298
306
  </TransitionProgressContext.Provider>
299
307
  )}
@@ -337,6 +345,20 @@ function ScreenContainer(props: ScreenContainerProps) {
337
345
  return <View {...rest} />;
338
346
  }
339
347
 
348
+ function FullWindowOverlay(props: { children: ReactNode }) {
349
+ if (Platform.OS !== 'ios') {
350
+ console.warn('Importing FullWindowOverlay is only valid on iOS devices.');
351
+ return <View {...props} />;
352
+ }
353
+ return (
354
+ <ScreensNativeModules.NativeFullWindowOverlay
355
+ style={{ position: 'absolute', width: '100%', height: '100%' }}
356
+ >
357
+ {props.children}
358
+ </ScreensNativeModules.NativeFullWindowOverlay>
359
+ );
360
+ }
361
+
340
362
  const styles = StyleSheet.create({
341
363
  headerSubview: {
342
364
  position: 'absolute',
@@ -351,7 +373,8 @@ const styles = StyleSheet.create({
351
373
  const ScreenStackHeaderBackButtonImage = (props: ImageProps): JSX.Element => (
352
374
  <ScreensNativeModules.NativeScreenStackHeaderSubview
353
375
  type="back"
354
- style={styles.headerSubview}>
376
+ style={styles.headerSubview}
377
+ >
355
378
  <Image resizeMode="center" fadeDuration={0} {...props} />
356
379
  </ScreensNativeModules.NativeScreenStackHeaderSubview>
357
380
  );
@@ -431,6 +454,7 @@ module.exports = {
431
454
  ScreenContext,
432
455
  ScreenStack,
433
456
  InnerScreen,
457
+ FullWindowOverlay,
434
458
 
435
459
  get NativeScreen() {
436
460
  return ScreensNativeModules.NativeScreen;
@@ -460,14 +484,6 @@ module.exports = {
460
484
 
461
485
  return ScreensNativeModules.NativeSearchBar;
462
486
  },
463
- get FullWindowOverlay() {
464
- if (Platform.OS !== 'ios') {
465
- console.warn('Importing FullWindowOverlay is only valid on iOS devices.');
466
- return View;
467
- }
468
-
469
- return ScreensNativeModules.NativeFullWindowOverlay;
470
- },
471
487
  // these are functions and will not be evaluated until used
472
488
  // so no need to use getters for them
473
489
  ScreenStackHeaderBackButtonImage,
package/src/index.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { Animated, View, ViewProps, ImageProps, Image } from 'react-native';
3
3
  import {
4
4
  ScreenProps,
@@ -68,13 +68,17 @@ export const ScreenContext = React.createContext(Screen);
68
68
 
69
69
  export const ScreenContainer: React.ComponentType<ScreenContainerProps> = View;
70
70
 
71
- export const NativeScreenContainer: React.ComponentType<ScreenContainerProps> = View;
71
+ export const NativeScreenContainer: React.ComponentType<ScreenContainerProps> =
72
+ View;
72
73
 
73
- export const NativeScreenNavigationContainer: React.ComponentType<ScreenContainerProps> = View;
74
+ export const NativeScreenNavigationContainer: React.ComponentType<ScreenContainerProps> =
75
+ View;
74
76
 
75
77
  export const ScreenStack: React.ComponentType<ScreenStackProps> = View;
76
78
 
77
- export const FullWindowOverlay = View;
79
+ export const FullWindowOverlay = View as React.ComponentType<{
80
+ children: ReactNode;
81
+ }>;
78
82
 
79
83
  export const ScreenStackHeaderBackButtonImage = (
80
84
  props: ImageProps
@@ -100,13 +104,14 @@ export const ScreenStackHeaderSearchBarView = (
100
104
  props: React.PropsWithChildren<SearchBarProps>
101
105
  ): JSX.Element => <View {...props} />;
102
106
 
103
- export const ScreenStackHeaderConfig: React.ComponentType<ScreenStackHeaderConfigProps> = View;
107
+ export const ScreenStackHeaderConfig: React.ComponentType<ScreenStackHeaderConfigProps> =
108
+ View;
104
109
 
105
110
  // @ts-expect-error: search bar props have no common props with View
106
111
  export const SearchBar: React.ComponentType<SearchBarProps> = View;
107
112
 
108
- export const ScreenStackHeaderSubview: React.ComponentType<React.PropsWithChildren<
109
- ViewProps & { type?: HeaderSubviewTypes }
110
- >> = View;
113
+ export const ScreenStackHeaderSubview: React.ComponentType<
114
+ React.PropsWithChildren<ViewProps & { type?: HeaderSubviewTypes }>
115
+ > = View;
111
116
 
112
117
  export const shouldUseActivityState = true;
@@ -382,11 +382,10 @@ export type NativeStackNavigationOptions = {
382
382
  transitionDuration?: number;
383
383
  };
384
384
 
385
- export type NativeStackNavigatorProps = DefaultNavigatorOptions<
386
- NativeStackNavigationOptions
387
- > &
388
- StackRouterOptions &
389
- NativeStackNavigationConfig;
385
+ export type NativeStackNavigatorProps =
386
+ DefaultNavigatorOptions<NativeStackNavigationOptions> &
387
+ StackRouterOptions &
388
+ NativeStackNavigationConfig;
390
389
 
391
390
  export type NativeStackDescriptor = Descriptor<
392
391
  ParamListBase,
@@ -65,15 +65,12 @@ export default function HeaderConfig({
65
65
  isDisabled: !searchBar || !!searchBar.disableBackButtonOverride,
66
66
  });
67
67
 
68
- const [
69
- backTitleFontFamily,
70
- largeTitleFontFamily,
71
- titleFontFamily,
72
- ] = processFonts([
73
- headerBackTitleStyle.fontFamily,
74
- headerLargeTitleStyle.fontFamily,
75
- headerTitleStyle.fontFamily,
76
- ]);
68
+ const [backTitleFontFamily, largeTitleFontFamily, titleFontFamily] =
69
+ processFonts([
70
+ headerBackTitleStyle.fontFamily,
71
+ headerLargeTitleStyle.fontFamily,
72
+ headerTitleStyle.fontFamily,
73
+ ]);
77
74
 
78
75
  // We want to clear clearSubscription only when components unmounts or search bar changes
79
76
  React.useEffect(() => clearSubscription, [searchBar]);
@@ -141,7 +138,8 @@ export default function HeaderConfig({
141
138
  topInsetEnabled={headerTopInsetEnabled}
142
139
  translucent={headerTranslucent === true}
143
140
  onAttached={handleAttached}
144
- onDetached={handleDetached}>
141
+ onDetached={handleDetached}
142
+ >
145
143
  {headerRight !== undefined ? (
146
144
  <ScreenStackHeaderRightView>
147
145
  {headerRight({ tintColor })}
@@ -98,7 +98,8 @@ const MaybeNestedStack = ({
98
98
  contentStyle,
99
99
  ]}
100
100
  // @ts-ignore Wrong props passed to View
101
- stackPresentation={stackPresentation}>
101
+ stackPresentation={stackPresentation}
102
+ >
102
103
  {children}
103
104
  </Container>
104
105
  );
@@ -293,16 +294,19 @@ const RouteView = ({
293
294
  source: route.key,
294
295
  target: stateKey,
295
296
  });
296
- }}>
297
+ }}
298
+ >
297
299
  <HeaderHeightContext.Provider
298
300
  value={
299
301
  isHeaderInPush !== false ? headerHeight : parentHeaderHeight ?? 0
300
- }>
302
+ }
303
+ >
301
304
  <HeaderConfig {...options} route={route} headerShown={isHeaderInPush} />
302
305
  <MaybeNestedStack
303
306
  options={options}
304
307
  route={route}
305
- stackPresentation={stackPresentation}>
308
+ stackPresentation={stackPresentation}
309
+ >
306
310
  {renderScene()}
307
311
  </MaybeNestedStack>
308
312
  </HeaderHeightContext.Provider>
@@ -11,7 +11,7 @@ import Animated, { useEvent, useSharedValue } from 'react-native-reanimated';
11
11
  import ReanimatedTransitionProgressContext from './ReanimatedTransitionProgressContext';
12
12
 
13
13
  const AnimatedScreen = Animated.createAnimatedComponent(
14
- (InnerScreen as unknown) as React.ComponentClass
14
+ InnerScreen as unknown as React.ComponentClass
15
15
  );
16
16
 
17
17
  // We use prop added to global by reanimated since it seems safer than the one from RN. See:
@@ -51,13 +51,15 @@ const ReanimatedNativeStackScreen = React.forwardRef<
51
51
  : 'topTransitionProgress',
52
52
  ]
53
53
  )}
54
- {...rest}>
54
+ {...rest}
55
+ >
55
56
  <ReanimatedTransitionProgressContext.Provider
56
57
  value={{
57
58
  progress: progress,
58
59
  closing: closing,
59
60
  goingForward: goingForward,
60
- }}>
61
+ }}
62
+ >
61
63
  {children}
62
64
  </ReanimatedTransitionProgressContext.Provider>
63
65
  </AnimatedScreen>
@@ -5,7 +5,7 @@ import { InnerScreen, ScreenProps } from 'react-native-screens';
5
5
  import Animated from 'react-native-reanimated';
6
6
 
7
7
  const AnimatedScreen = Animated.createAnimatedComponent(
8
- (InnerScreen as unknown) as React.ComponentClass
8
+ InnerScreen as unknown as React.ComponentClass
9
9
  );
10
10
 
11
11
  const ReanimatedScreen = React.forwardRef<typeof AnimatedScreen, ScreenProps>(