@umituz/react-native-bottom-sheet 1.1.0 → 1.1.1

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.0",
3
+ "version": "1.1.1",
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",
@@ -29,7 +29,7 @@
29
29
  * ```
30
30
  */
31
31
 
32
- import React, { forwardRef, useCallback, useMemo } from 'react';
32
+ import React, { forwardRef, useCallback, useMemo, useEffect, useState } from 'react';
33
33
  import { StyleSheet } from 'react-native';
34
34
  import GorhomBottomSheet, {
35
35
  BottomSheetView,
@@ -154,23 +154,44 @@ export const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
154
154
  ) => {
155
155
  const tokens = useAppDesignTokens();
156
156
  const sheetRef = React.useRef<GorhomBottomSheet>(null);
157
+ const [isMounted, setIsMounted] = useState(false);
158
+
159
+ // Ensure component is mounted after Reanimated is ready
160
+ // This prevents layoutState.get errors during initial render
161
+ useEffect(() => {
162
+ // Use requestAnimationFrame to ensure Reanimated is initialized
163
+ const timer = requestAnimationFrame(() => {
164
+ setIsMounted(true);
165
+ });
166
+ return () => cancelAnimationFrame(timer);
167
+ }, []);
157
168
 
158
169
  // Expose ref methods
159
170
  React.useImperativeHandle(ref, () => ({
160
171
  snapToIndex: (index: number) => {
161
- sheetRef.current?.snapToIndex(index);
172
+ if (isMounted) {
173
+ sheetRef.current?.snapToIndex(index);
174
+ }
162
175
  },
163
176
  snapToPosition: (position: string | number) => {
164
- sheetRef.current?.snapToPosition(position);
177
+ if (isMounted) {
178
+ sheetRef.current?.snapToPosition(position);
179
+ }
165
180
  },
166
181
  expand: () => {
167
- sheetRef.current?.expand();
182
+ if (isMounted) {
183
+ sheetRef.current?.expand();
184
+ }
168
185
  },
169
186
  collapse: () => {
170
- sheetRef.current?.collapse();
187
+ if (isMounted) {
188
+ sheetRef.current?.collapse();
189
+ }
171
190
  },
172
191
  close: () => {
173
- sheetRef.current?.close();
192
+ if (isMounted) {
193
+ sheetRef.current?.close();
194
+ }
174
195
  },
175
196
  }));
176
197
 
@@ -229,6 +250,11 @@ export const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
229
250
  [onChange, onClose]
230
251
  );
231
252
 
253
+ // Don't render until Reanimated is ready to prevent layoutState errors
254
+ if (!isMounted) {
255
+ return null;
256
+ }
257
+
232
258
  return (
233
259
  <GorhomBottomSheet
234
260
  ref={sheetRef}
@@ -30,7 +30,7 @@
30
30
  * ```
31
31
  */
32
32
 
33
- import React, { forwardRef, useCallback, useMemo } from 'react';
33
+ import React, { forwardRef, useCallback, useMemo, useEffect, useState } from 'react';
34
34
  import { StyleSheet } from 'react-native';
35
35
  import {
36
36
  BottomSheetModal as GorhomBottomSheetModal,
@@ -156,26 +156,49 @@ export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModal
156
156
  ) => {
157
157
  const tokens = useAppDesignTokens();
158
158
  const modalRef = React.useRef<GorhomBottomSheetModal>(null);
159
+ const [isMounted, setIsMounted] = useState(false);
160
+
161
+ // Ensure component is mounted after Reanimated is ready
162
+ // This prevents layoutState.get errors during initial render
163
+ useEffect(() => {
164
+ // Use requestAnimationFrame to ensure Reanimated is initialized
165
+ const timer = requestAnimationFrame(() => {
166
+ setIsMounted(true);
167
+ });
168
+ return () => cancelAnimationFrame(timer);
169
+ }, []);
159
170
 
160
171
  // Expose ref methods
161
172
  React.useImperativeHandle(ref, () => ({
162
173
  present: () => {
163
- modalRef.current?.present();
174
+ if (isMounted) {
175
+ modalRef.current?.present();
176
+ }
164
177
  },
165
178
  dismiss: () => {
166
- modalRef.current?.dismiss();
179
+ if (isMounted) {
180
+ modalRef.current?.dismiss();
181
+ }
167
182
  },
168
183
  snapToIndex: (index: number) => {
169
- modalRef.current?.snapToIndex(index);
184
+ if (isMounted) {
185
+ modalRef.current?.snapToIndex(index);
186
+ }
170
187
  },
171
188
  snapToPosition: (position: string | number) => {
172
- modalRef.current?.snapToPosition(position);
189
+ if (isMounted) {
190
+ modalRef.current?.snapToPosition(position);
191
+ }
173
192
  },
174
193
  expand: () => {
175
- modalRef.current?.expand();
194
+ if (isMounted) {
195
+ modalRef.current?.expand();
196
+ }
176
197
  },
177
198
  collapse: () => {
178
- modalRef.current?.collapse();
199
+ if (isMounted) {
200
+ modalRef.current?.collapse();
201
+ }
179
202
  },
180
203
  }));
181
204
 
@@ -234,6 +257,11 @@ export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModal
234
257
  [onChange, onDismiss]
235
258
  );
236
259
 
260
+ // Don't render until Reanimated is ready to prevent layoutState errors
261
+ if (!isMounted) {
262
+ return null;
263
+ }
264
+
237
265
  return (
238
266
  <GorhomBottomSheetModal
239
267
  ref={modalRef}