Skip to content

Commit ca0913a

Browse files
authored
fix(Android,native-stack): fix check for sheetAllowedDetents value & apply appropriate styles (#2762)
## Description I've made a small change in v5 code in #2748, however due to my overlook it introduced a regression in native-stack v5. Since it is a quick fix I'm patching it. Basically I've parsed & transformed `sheetAllowedDetents` value in `RouteView`, **before** passing it to `MaybeNestedStack`, where I've checked for `sheetAllowedDetents === 'fitToContents'`, which could not be true, because in such case it has been transformed to `[-1]` literal in `RouteView`. Only the latest 4.10.0-beta.0 & beta.1 versions are affected. ## Changes Removed `sheetAllowedDetents` prop value transformation in `RouteView` since `Screen` component handles it nicely internally. ## Test code and steps to reproduce `TestFormSheet`, but you need to run it using `createNativeStackNavigator` from `react-native-screens/native-stack`. Don't forget to change the `presentation` prop to `stackPresentation`, when changing to v5. ## Checklist - [ ] Ensured that CI passes
1 parent c8903e5 commit ca0913a

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/components/Screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function resolveSheetAllowedDetents(
9696
return SHEET_COMPAT_ALL;
9797
} else {
9898
// Safe default, only large detent is allowed.
99-
return [1.0];
99+
return SHEET_COMPAT_LARGE;
100100
}
101101
}
102102

src/native-stack/views/NativeStackView.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,19 @@ const MaybeNestedStack = ({
104104
headerShownPreviousRef.current = headerShown;
105105
}, [headerShown, stackPresentation, route.name]);
106106

107+
const formSheetAdjustedContentStyle =
108+
stackPresentation === 'formSheet'
109+
? Platform.OS === 'ios'
110+
? styles.absoluteFillNoBottom
111+
: sheetAllowedDetents === 'fitToContents'
112+
? null
113+
: styles.container
114+
: styles.container;
115+
107116
const content = (
108117
<Container
109118
style={[
110-
stackPresentation === 'formSheet'
111-
? Platform.OS === 'ios'
112-
? styles.absoluteFillNoBottom
113-
: sheetAllowedDetents === 'fitToContents'
114-
? null
115-
: styles.container
116-
: styles.container,
119+
formSheetAdjustedContentStyle,
117120
stackPresentation !== 'transparentModal' &&
118121
stackPresentation !== 'containedTransparentModal' && {
119122
backgroundColor: colors.background,
@@ -198,6 +201,7 @@ const RouteView = ({
198201
headerShown,
199202
hideKeyboardOnSwipe,
200203
homeIndicatorHidden,
204+
sheetAllowedDetents = [1.0],
201205
sheetLargestUndimmedDetentIndex = 'none',
202206
sheetGrabberVisible = false,
203207
sheetCornerRadius = -1.0,
@@ -223,7 +227,6 @@ const RouteView = ({
223227
} = options;
224228

225229
let {
226-
sheetAllowedDetents = [1.0],
227230
customAnimationOnSwipe,
228231
fullScreenSwipeEnabled,
229232
gestureResponseDistance,
@@ -243,10 +246,6 @@ const RouteView = ({
243246
};
244247
}
245248

246-
if (sheetAllowedDetents === 'fitToContents') {
247-
sheetAllowedDetents = [-1];
248-
}
249-
250249
if (swipeDirection === 'vertical') {
251250
// for `vertical` direction to work, we need to set `fullScreenSwipeEnabled` to `true`
252251
// so the screen can be dismissed from any point on screen.

0 commit comments

Comments
 (0)