Skip to content

Commit e694bf6

Browse files
committed
feat: update bottom sheet widget
1 parent 3b14dfa commit e694bf6

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/pluggableWidgets/bottom-sheet-native/src/components/ExpandingDrawer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export const ExpandingDrawer = (props: ExpandingDrawerProps): ReactElement => {
7373
return [heightHeader];
7474
}, [props.fullscreenContent, heightContent, fullscreenHeight, heightHeader, isLargeContentValid]);
7575

76+
const offsetSnapPoints = useMemo(() => snapPoints.map(p => p + OFFSET_BOTTOM_SHEET), [snapPoints]);
77+
7678
const renderContent = useCallback((): ReactNode => {
7779
const content = (
7880
<View onLayout={onLayoutHandlerContent} pointerEvents="box-none">
@@ -141,7 +143,7 @@ export const ExpandingDrawer = (props: ExpandingDrawerProps): ReactElement => {
141143
<BottomSheet
142144
ref={bottomSheetRef}
143145
index={collapsedIndex}
144-
snapPoints={snapPoints.map(p => p + OFFSET_BOTTOM_SHEET)}
146+
snapPoints={offsetSnapPoints}
145147
onClose={() => setIsOpen(false)}
146148
enablePanDownToClose={false}
147149
onChange={onChange}

packages/pluggableWidgets/bottom-sheet-native/src/components/NativeBottomSheet.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ReactElement, useCallback, useEffect, useRef } from "react";
1+
import { ReactElement, useCallback, useEffect, useMemo, useRef } from "react";
22
import {
33
ActionSheetIOS,
44
Appearance,
5+
Dimensions,
56
Modal,
67
Platform,
78
Pressable,
@@ -29,6 +30,18 @@ let lastIndexRef = -1;
2930
export const NativeBottomSheet = (props: NativeBottomSheetProps): ReactElement => {
3031
const bottomSheetRef = useRef<BottomSheet>(null);
3132

33+
const snapPoints = useMemo(() => {
34+
// @gorhom/bottom-sheet relies on Reanimated worklets; passing a stable snapPoints array
35+
// avoids UI-thread "non-worklet function" crashes caused by unstable/undefined inputs.
36+
const itemCount = props.itemsBasic.length;
37+
const itemHeight = 44;
38+
const verticalPadding = 24;
39+
const maxHeight = Dimensions.get("window").height * 0.9;
40+
const estimatedHeight = itemCount * itemHeight + verticalPadding;
41+
42+
return [Math.min(maxHeight, estimatedHeight)];
43+
}, [props.itemsBasic.length]);
44+
3245
const isAvailable = props.triggerAttribute && props.triggerAttribute.status === ValueStatus.Available;
3346
const isOpen =
3447
props.triggerAttribute &&
@@ -139,12 +152,12 @@ export const NativeBottomSheet = (props: NativeBottomSheetProps): ReactElement =
139152
);
140153
};
141154

142-
const getContainerStyle = () => {
155+
const containerStyle = useMemo(() => {
143156
if (props.useNative) {
144157
return [nativeAndroidStyles.sheetContainer];
145158
}
146159
return [styles.sheetContainer, props.styles.container];
147-
};
160+
}, [props.useNative, props.styles.container]);
148161

149162
const handleSheetChanges = (index: number) => {
150163
if (!isAvailable) {
@@ -175,11 +188,12 @@ export const NativeBottomSheet = (props: NativeBottomSheetProps): ReactElement =
175188
<BottomSheet
176189
ref={bottomSheetRef}
177190
index={isOpen ? 0 : -1} // Start closed.
191+
snapPoints={snapPoints}
178192
enablePanDownToClose
179193
animateOnMount
180194
onClose={() => handleSheetChanges(-1)}
181195
onChange={handleSheetChanges}
182-
style={getContainerStyle()}
196+
style={containerStyle}
183197
backdropComponent={renderBackdrop}
184198
backgroundStyle={props.styles.container}
185199
handleComponent={null}

0 commit comments

Comments
 (0)