@umituz/react-native-bottom-sheet 1.1.5 → 1.1.7
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-bottom-sheet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Modern, performant bottom sheets for React Native with preset configurations, keyboard handling, and smooth animations",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -158,6 +158,35 @@ export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModal
|
|
|
158
158
|
const modalRef = React.useRef<GorhomBottomSheetModal>(null);
|
|
159
159
|
const [isMounted, setIsMounted] = useState(false);
|
|
160
160
|
|
|
161
|
+
// Get configuration from preset or custom (must be before useImperativeHandle)
|
|
162
|
+
const config: BottomSheetConfig = useMemo(() => {
|
|
163
|
+
if (customSnapPoints) {
|
|
164
|
+
return BottomSheetUtils.createConfig({
|
|
165
|
+
snapPoints: customSnapPoints,
|
|
166
|
+
initialIndex,
|
|
167
|
+
enableBackdrop,
|
|
168
|
+
backdropAppearsOnIndex,
|
|
169
|
+
backdropDisappearsOnIndex,
|
|
170
|
+
keyboardBehavior,
|
|
171
|
+
enableHandleIndicator,
|
|
172
|
+
enablePanDownToClose,
|
|
173
|
+
enableDynamicSizing,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return BottomSheetUtils.getPreset(preset);
|
|
177
|
+
}, [
|
|
178
|
+
preset,
|
|
179
|
+
customSnapPoints,
|
|
180
|
+
initialIndex,
|
|
181
|
+
enableBackdrop,
|
|
182
|
+
backdropAppearsOnIndex,
|
|
183
|
+
backdropDisappearsOnIndex,
|
|
184
|
+
keyboardBehavior,
|
|
185
|
+
enableHandleIndicator,
|
|
186
|
+
enablePanDownToClose,
|
|
187
|
+
enableDynamicSizing,
|
|
188
|
+
]);
|
|
189
|
+
|
|
161
190
|
// Ensure component is mounted after Reanimated is ready
|
|
162
191
|
// This prevents layoutState.get errors during initial render
|
|
163
192
|
// @gorhom/bottom-sheet uses useAnimatedDetents which accesses layoutState.get
|
|
@@ -182,16 +211,38 @@ export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModal
|
|
|
182
211
|
};
|
|
183
212
|
}, []);
|
|
184
213
|
|
|
185
|
-
//
|
|
214
|
+
// Render backdrop component (must be before early return to maintain hook order)
|
|
215
|
+
const renderBackdrop = useCallback(
|
|
216
|
+
(props: BottomSheetBackdropProps) =>
|
|
217
|
+
enableBackdrop ? (
|
|
218
|
+
<BottomSheetBackdrop
|
|
219
|
+
{...props}
|
|
220
|
+
appearsOnIndex={config.backdropAppearsOnIndex ?? 0}
|
|
221
|
+
disappearsOnIndex={config.backdropDisappearsOnIndex ?? -1}
|
|
222
|
+
opacity={0.5}
|
|
223
|
+
pressBehavior="close"
|
|
224
|
+
/>
|
|
225
|
+
) : null,
|
|
226
|
+
[enableBackdrop, config.backdropAppearsOnIndex, config.backdropDisappearsOnIndex]
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// Handle sheet changes (must be before early return to maintain hook order)
|
|
230
|
+
const handleSheetChange = useCallback(
|
|
231
|
+
(index: number) => {
|
|
232
|
+
onChange?.(index);
|
|
233
|
+
if (index === -1) {
|
|
234
|
+
onDismiss?.();
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
[onChange, onDismiss]
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// Expose ref methods (must be before early return to maintain hook order)
|
|
186
241
|
React.useImperativeHandle(ref, () => ({
|
|
187
242
|
present: () => {
|
|
188
|
-
if (isMounted) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const initialIdx = initialIndex ?? config.initialIndex ?? 0;
|
|
192
|
-
setTimeout(() => {
|
|
193
|
-
modalRef.current?.snapToIndex(initialIdx);
|
|
194
|
-
}, 100);
|
|
243
|
+
if (isMounted && modalRef.current) {
|
|
244
|
+
// @gorhom/bottom-sheet's present() automatically opens from bottom to first snap point
|
|
245
|
+
modalRef.current.present();
|
|
195
246
|
}
|
|
196
247
|
},
|
|
197
248
|
dismiss: () => {
|
|
@@ -223,36 +274,11 @@ export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModal
|
|
|
223
274
|
|
|
224
275
|
// Don't render until mounted to prevent early hook execution
|
|
225
276
|
// This ensures @gorhom/bottom-sheet's internal hooks don't run before Reanimated is ready
|
|
277
|
+
// IMPORTANT: All hooks must be called before this early return to maintain hook order
|
|
226
278
|
if (!isMounted) {
|
|
227
279
|
return null;
|
|
228
280
|
}
|
|
229
281
|
|
|
230
|
-
// Render backdrop component
|
|
231
|
-
const renderBackdrop = useCallback(
|
|
232
|
-
(props: BottomSheetBackdropProps) =>
|
|
233
|
-
enableBackdrop ? (
|
|
234
|
-
<BottomSheetBackdrop
|
|
235
|
-
{...props}
|
|
236
|
-
appearsOnIndex={config.backdropAppearsOnIndex ?? 0}
|
|
237
|
-
disappearsOnIndex={config.backdropDisappearsOnIndex ?? -1}
|
|
238
|
-
opacity={0.5}
|
|
239
|
-
pressBehavior="close"
|
|
240
|
-
/>
|
|
241
|
-
) : null,
|
|
242
|
-
[enableBackdrop, config.backdropAppearsOnIndex, config.backdropDisappearsOnIndex]
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
// Handle sheet changes
|
|
246
|
-
const handleSheetChange = useCallback(
|
|
247
|
-
(index: number) => {
|
|
248
|
-
onChange?.(index);
|
|
249
|
-
if (index === -1) {
|
|
250
|
-
onDismiss?.();
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
[onChange, onDismiss]
|
|
254
|
-
);
|
|
255
|
-
|
|
256
282
|
return (
|
|
257
283
|
<GorhomBottomSheetModal
|
|
258
284
|
ref={modalRef}
|