Skip to content

Commit 9e1f1db

Browse files
committed
bring back provided contentHeight and handleHeight, and disable default dynamic sizing
not sure why provided content + handle height was removed in gorhom#1683, it significantly increases the mount cost because it now requires a full off-screen render pass of the content and handle components before the sheet can be displayed
1 parent 59f6ad9 commit 9e1f1db

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ const BottomSheetComponent = forwardRef<BottomSheetMethods, BottomSheetProps>(
123123
android_keyboardInputMode = DEFAULT_KEYBOARD_INPUT_MODE,
124124

125125
// layout
126+
handleHeight: _providedHandleHeight,
126127
containerHeight: _providedContainerHeight,
128+
contentHeight: _providedContentHeight,
127129
containerOffset: _providedContainerOffset,
128130
topInset = 0,
129131
bottomInset = 0,
@@ -202,11 +204,13 @@ const BottomSheetComponent = forwardRef<BottomSheetMethods, BottomSheetProps>(
202204
const animatedContainerOffset = useReactiveSharedValue(
203205
_providedContainerOffset ?? INITIAL_CONTAINER_OFFSET
204206
) as Animated.SharedValue<Insets>;
205-
const animatedHandleHeight = useReactiveSharedValue<number>(
206-
INITIAL_HANDLE_HEIGHT
207+
const animatedHandleHeight = useReactiveSharedValue(
208+
_providedHandleHeight ?? INITIAL_HANDLE_HEIGHT
207209
);
208210
const animatedFooterHeight = useSharedValue(0);
209-
const animatedContentHeight = useSharedValue(INITIAL_CONTAINER_HEIGHT);
211+
const animatedContentHeight = useReactiveSharedValue(
212+
_providedContentHeight ?? INITIAL_CONTAINER_HEIGHT
213+
);
210214
const [animatedSnapPoints, animatedDynamicSnapPointIndex] =
211215
useNormalizedSnapPoints(
212216
_providedSnapPoints,
@@ -258,6 +262,14 @@ const BottomSheetComponent = forwardRef<BottomSheetMethods, BottomSheetProps>(
258262
}
259263

260264
let isHandleHeightCalculated = false;
265+
// handle height is provided.
266+
if (
267+
_providedHandleHeight !== null &&
268+
_providedHandleHeight !== undefined &&
269+
typeof _providedHandleHeight === 'number'
270+
) {
271+
isHandleHeightCalculated = true;
272+
}
261273
// handle component is null.
262274
if (handleComponent === null) {
263275
animatedHandleHeight.value = 0;
@@ -281,9 +293,10 @@ const BottomSheetComponent = forwardRef<BottomSheetMethods, BottomSheetProps>(
281293
);
282294
}, [
283295
_providedContainerHeight,
284-
animatedContainerHeight.value,
296+
_providedHandleHeight,
297+
animatedContainerHeight,
285298
animatedHandleHeight,
286-
animatedSnapPoints.value,
299+
animatedSnapPoints,
287300
handleComponent,
288301
]);
289302
const isInTemporaryPosition = useSharedValue(false);
@@ -1271,6 +1284,14 @@ const BottomSheetComponent = forwardRef<BottomSheetMethods, BottomSheetProps>(
12711284
[_providedStyle, containerAnimatedStyle]
12721285
);
12731286
const contentContainerAnimatedStyle = useAnimatedStyle(() => {
1287+
/**
1288+
* if content height was provided, then we skip setting
1289+
* calculated height.
1290+
*/
1291+
if (_providedContentHeight) {
1292+
return {};
1293+
}
1294+
12741295
/**
12751296
* if dynamic sizing is enabled, and content height
12761297
* is still not set, then we exit method.
@@ -1290,9 +1311,10 @@ const BottomSheetComponent = forwardRef<BottomSheetMethods, BottomSheetProps>(
12901311
};
12911312
}, [
12921313
enableDynamicSizing,
1293-
animatedContentHeight.value,
1294-
animatedContentHeightMax.value,
1314+
animatedContentHeight,
1315+
animatedContentHeightMax,
12951316
_providedAnimationConfigs,
1317+
_providedContentHeight,
12961318
]);
12971319
const contentContainerStyle = useMemo(
12981320
() => [styles.contentContainer, contentContainerAnimatedStyle],

src/components/bottomSheet/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const DEFAULT_ENABLE_HANDLE_PANNING_GESTURE = true;
1313
const DEFAULT_ENABLE_OVER_DRAG = true;
1414
const DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE = false;
1515
const DEFAULT_ANIMATE_ON_MOUNT = true;
16-
const DEFAULT_DYNAMIC_SIZING = true;
16+
const DEFAULT_DYNAMIC_SIZING = false;
1717

1818
// keyboard
1919
const DEFAULT_KEYBOARD_BEHAVIOR = KEYBOARD_BEHAVIOR.interactive;

src/components/bottomSheet/types.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,25 @@ export interface BottomSheetProps
104104
//#endregion
105105

106106
//#region layout
107+
/**
108+
* Handle height helps to calculate the internal container and sheet layouts,
109+
* if `handleComponent` is provided, the library internally will calculate its layout,
110+
* unless `handleHeight` is provided.
111+
* @type number | SharedValue<number>;
112+
*/
113+
handleHeight?: number | SharedValue<number>;
107114
/**
108115
* Container height helps to calculate the internal sheet layouts,
109116
* if `containerHeight` not provided, the library internally will calculate it,
110117
* however this will cause an extra re-rendering.
111118
* @type number | SharedValue<number>;
112119
*/
113120
containerHeight?: number | SharedValue<number>;
121+
/**
122+
* Content height helps dynamic snap points calculation.
123+
* @type number | SharedValue<number>;
124+
*/
125+
contentHeight?: number | SharedValue<number>;
114126
/**
115127
* Container offset helps to accurately detect container offsets.
116128
* @type SharedValue<number>;

0 commit comments

Comments
 (0)