@react-navigation/native-stack 7.0.0-alpha.7 → 7.0.0-alpha.9

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.
@@ -104,7 +104,12 @@ const MaybeNestedStack = ({
104
104
  if (isHeaderInModal) {
105
105
  return (
106
106
  <ScreenStack style={styles.container}>
107
- <Screen enabled style={StyleSheet.absoluteFill}>
107
+ <Screen
108
+ enabled
109
+ isNativeStack
110
+ hasLargeHeader={options.headerLargeTitle ?? false}
111
+ style={StyleSheet.absoluteFill}
112
+ >
108
113
  {content}
109
114
  <HeaderConfig
110
115
  {...options}
@@ -128,11 +133,13 @@ type SceneViewProps = {
128
133
  previousDescriptor?: NativeStackDescriptor;
129
134
  nextDescriptor?: NativeStackDescriptor;
130
135
  onWillDisappear: () => void;
136
+ onWillAppear: () => void;
131
137
  onAppear: () => void;
132
138
  onDisappear: () => void;
133
139
  onDismissed: ScreenProps['onDismissed'];
134
140
  onHeaderBackButtonClicked: ScreenProps['onHeaderBackButtonClicked'];
135
141
  onNativeDismissCancelled: ScreenProps['onDismissed'];
142
+ onGestureCancel: ScreenProps['onGestureCancel'];
136
143
  };
137
144
 
138
145
  const SceneView = ({
@@ -142,11 +149,13 @@ const SceneView = ({
142
149
  previousDescriptor,
143
150
  nextDescriptor,
144
151
  onWillDisappear,
152
+ onWillAppear,
145
153
  onAppear,
146
154
  onDisappear,
147
155
  onDismissed,
148
156
  onHeaderBackButtonClicked,
149
157
  onNativeDismissCancelled,
158
+ onGestureCancel,
150
159
  }: SceneViewProps) => {
151
160
  const { route, navigation, options, render } = descriptor;
152
161
 
@@ -162,20 +171,27 @@ const SceneView = ({
162
171
  animationTypeForReplace = 'push',
163
172
  gestureEnabled,
164
173
  gestureDirection = presentation === 'card' ? 'horizontal' : 'vertical',
174
+ gestureResponseDistance,
165
175
  header,
166
176
  headerBackButtonMenuEnabled,
167
177
  headerShown,
168
178
  headerBackground,
169
179
  headerTransparent,
170
180
  autoHideHomeIndicator,
181
+ keyboardHandlingEnabled,
171
182
  navigationBarColor,
172
183
  navigationBarHidden,
173
184
  orientation,
185
+ sheetAllowedDetents = 'large',
186
+ sheetLargestUndimmedDetent = 'all',
187
+ sheetGrabberVisible = false,
188
+ sheetCornerRadius = -1.0,
189
+ sheetExpandsWhenScrolledToEdge = true,
174
190
  statusBarAnimation,
175
191
  statusBarHidden,
176
192
  statusBarStyle,
177
193
  statusBarTranslucent,
178
- statusBarColor,
194
+ statusBarBackgroundColor,
179
195
  freezeOnBlur,
180
196
  } = options;
181
197
 
@@ -231,17 +247,9 @@ const SceneView = ({
231
247
  ? 0
232
248
  : insets.top;
233
249
 
234
- // On models with Dynamic Island the status bar height is smaller than the safe area top inset.
235
- const hasDynamicIsland = Platform.OS === 'ios' && topInset > 50;
236
- const statusBarHeight = hasDynamicIsland ? topInset - 5 : topInset;
237
-
238
250
  const { preventedRoutes } = usePreventRemoveContext();
239
251
 
240
- const defaultHeaderHeight = getDefaultHeaderHeight(
241
- frame,
242
- isModal,
243
- statusBarHeight
244
- );
252
+ const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);
245
253
 
246
254
  const [customHeaderHeight, setCustomHeaderHeight] =
247
255
  React.useState(defaultHeaderHeight);
@@ -270,7 +278,9 @@ const SceneView = ({
270
278
  <Screen
271
279
  key={route.key}
272
280
  enabled
281
+ isNativeStack
273
282
  style={StyleSheet.absoluteFill}
283
+ hasLargeHeader={options.headerLargeTitle ?? false}
274
284
  customAnimationOnSwipe={animationMatchesGesture}
275
285
  fullScreenSwipeEnabled={fullScreenGestureEnabled}
276
286
  gestureEnabled={
@@ -281,29 +291,36 @@ const SceneView = ({
281
291
  : gestureEnabled
282
292
  }
283
293
  homeIndicatorHidden={autoHideHomeIndicator}
294
+ hideKeyboardOnSwipe={keyboardHandlingEnabled}
284
295
  navigationBarColor={navigationBarColor}
285
296
  navigationBarHidden={navigationBarHidden}
286
297
  replaceAnimation={animationTypeForReplace}
287
298
  stackPresentation={presentation === 'card' ? 'push' : presentation}
288
299
  stackAnimation={animation}
289
300
  screenOrientation={orientation}
301
+ sheetAllowedDetents={sheetAllowedDetents}
302
+ sheetLargestUndimmedDetent={sheetLargestUndimmedDetent}
303
+ sheetGrabberVisible={sheetGrabberVisible}
304
+ sheetCornerRadius={sheetCornerRadius}
305
+ sheetExpandsWhenScrolledToEdge={sheetExpandsWhenScrolledToEdge}
290
306
  statusBarAnimation={statusBarAnimation}
291
307
  statusBarHidden={statusBarHidden}
292
308
  statusBarStyle={statusBarStyle}
293
- statusBarColor={statusBarColor}
309
+ statusBarColor={statusBarBackgroundColor}
294
310
  statusBarTranslucent={statusBarTranslucent}
295
311
  swipeDirection={gestureDirectionOverride}
296
312
  transitionDuration={animationDuration}
313
+ onWillAppear={onWillAppear}
297
314
  onWillDisappear={onWillDisappear}
298
315
  onAppear={onAppear}
299
316
  onDisappear={onDisappear}
300
317
  onDismissed={onDismissed}
301
- isNativeStack
318
+ onGestureCancel={onGestureCancel}
319
+ gestureResponseDistance={gestureResponseDistance}
302
320
  nativeBackButtonDismissalEnabled={false} // on Android
303
321
  onHeaderBackButtonClicked={onHeaderBackButtonClicked}
304
322
  preventNativeDismiss={isRemovePrevented} // on iOS
305
323
  onNativeDismissCancelled={onNativeDismissCancelled}
306
- // @ts-expect-error this prop is available since rn-screens 3.26
307
324
  // Unfortunately, because of the bug that exists on Fabric, where native event drivers
308
325
  // for Animated objects are being created after the first notifications about the header height
309
326
  // from the native side, `onHeaderHeightChange` event does not notify
@@ -457,6 +474,13 @@ function NativeStackViewInner({ state, navigation, descriptors }: Props) {
457
474
  target: route.key,
458
475
  });
459
476
  }}
477
+ onWillAppear={() => {
478
+ navigation.emit({
479
+ type: 'transitionStart',
480
+ data: { closing: false },
481
+ target: route.key,
482
+ });
483
+ }}
460
484
  onAppear={() => {
461
485
  navigation.emit({
462
486
  type: 'transitionEnd',
@@ -494,6 +518,12 @@ function NativeStackViewInner({ state, navigation, descriptors }: Props) {
494
518
  target: state.key,
495
519
  });
496
520
  }}
521
+ onGestureCancel={() => {
522
+ navigation.emit({
523
+ type: 'gestureCancel',
524
+ target: route.key,
525
+ });
526
+ }}
497
527
  />
498
528
  );
499
529
  })}
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  type ParamListBase,
11
11
  type StackNavigationState,
12
- useLinkTools,
12
+ useLinkBuilder,
13
13
  } from '@react-navigation/native';
14
14
  import * as React from 'react';
15
15
  import { Image, StyleSheet, View } from 'react-native';
@@ -34,7 +34,13 @@ const TRANSPARENT_PRESENTATIONS = [
34
34
 
35
35
  export function NativeStackView({ state, descriptors }: Props) {
36
36
  const parentHeaderBack = React.useContext(HeaderBackContext);
37
- const { buildHref } = useLinkTools();
37
+ const { buildHref } = useLinkBuilder();
38
+
39
+ if (state.preloadedRoutes.length !== 0) {
40
+ throw new Error(
41
+ 'Preloading routes is not supported in the NativeStackNavigator navigator.'
42
+ );
43
+ }
38
44
 
39
45
  return (
40
46
  <SafeAreaProviderCompat>
@@ -114,29 +120,28 @@ export function NativeStackView({ state, descriptors }: Props) {
114
120
  label: headerBackTitle,
115
121
  })
116
122
  : headerLeft === undefined && canGoBack
117
- ? ({ tintColor }) => (
118
- <HeaderBackButton
119
- tintColor={tintColor}
120
- backImage={
121
- headerBackImageSource !== undefined
122
- ? () => (
123
- <Image
124
- source={headerBackImageSource}
125
- resizeMode="contain"
126
- style={[
127
- styles.backImage,
128
- { tintColor },
129
- ]}
130
- />
131
- )
132
- : undefined
133
- }
134
- canGoBack={canGoBack}
135
- onPress={navigation.goBack}
136
- href={headerBack.href}
137
- />
138
- )
139
- : headerLeft
123
+ ? ({ tintColor }) => (
124
+ <HeaderBackButton
125
+ tintColor={tintColor}
126
+ backImage={
127
+ headerBackImageSource !== undefined
128
+ ? () => (
129
+ <Image
130
+ source={headerBackImageSource}
131
+ resizeMode="contain"
132
+ style={[
133
+ styles.backImage,
134
+ { tintColor },
135
+ ]}
136
+ />
137
+ )
138
+ : undefined
139
+ }
140
+ onPress={navigation.goBack}
141
+ href={headerBack.href}
142
+ />
143
+ )
144
+ : headerLeft
140
145
  }
141
146
  headerRight={
142
147
  typeof headerRight === 'function'