@umituz/react-native-bottom-sheet 1.1.0 → 1.1.2
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.2",
|
|
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,59 @@ 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
|
+
// @gorhom/bottom-sheet uses useAnimatedDetents which accesses layoutState.get
|
|
162
|
+
// during initialization, so we need to wait for Reanimated to be fully ready
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
// Use a combination of setTimeout and requestAnimationFrame
|
|
165
|
+
// to ensure Reanimated is fully initialized before rendering
|
|
166
|
+
let frameId: number;
|
|
167
|
+
const timer = setTimeout(() => {
|
|
168
|
+
// Use multiple animation frames to ensure Reanimated worklets are ready
|
|
169
|
+
frameId = requestAnimationFrame(() => {
|
|
170
|
+
requestAnimationFrame(() => {
|
|
171
|
+
setIsMounted(true);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}, 150); // Increased delay to ensure Reanimated is fully initialized
|
|
175
|
+
|
|
176
|
+
return () => {
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
if (frameId) {
|
|
179
|
+
cancelAnimationFrame(frameId);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}, []);
|
|
157
183
|
|
|
158
184
|
// Expose ref methods
|
|
159
185
|
React.useImperativeHandle(ref, () => ({
|
|
160
186
|
snapToIndex: (index: number) => {
|
|
161
|
-
|
|
187
|
+
if (isMounted) {
|
|
188
|
+
sheetRef.current?.snapToIndex(index);
|
|
189
|
+
}
|
|
162
190
|
},
|
|
163
191
|
snapToPosition: (position: string | number) => {
|
|
164
|
-
|
|
192
|
+
if (isMounted) {
|
|
193
|
+
sheetRef.current?.snapToPosition(position);
|
|
194
|
+
}
|
|
165
195
|
},
|
|
166
196
|
expand: () => {
|
|
167
|
-
|
|
197
|
+
if (isMounted) {
|
|
198
|
+
sheetRef.current?.expand();
|
|
199
|
+
}
|
|
168
200
|
},
|
|
169
201
|
collapse: () => {
|
|
170
|
-
|
|
202
|
+
if (isMounted) {
|
|
203
|
+
sheetRef.current?.collapse();
|
|
204
|
+
}
|
|
171
205
|
},
|
|
172
206
|
close: () => {
|
|
173
|
-
|
|
207
|
+
if (isMounted) {
|
|
208
|
+
sheetRef.current?.close();
|
|
209
|
+
}
|
|
174
210
|
},
|
|
175
211
|
}));
|
|
176
212
|
|
|
@@ -229,6 +265,11 @@ export const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
|
|
|
229
265
|
[onChange, onClose]
|
|
230
266
|
);
|
|
231
267
|
|
|
268
|
+
// Don't render until Reanimated is ready to prevent layoutState errors
|
|
269
|
+
if (!isMounted) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
232
273
|
return (
|
|
233
274
|
<GorhomBottomSheet
|
|
234
275
|
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,64 @@ 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
|
+
// @gorhom/bottom-sheet uses useAnimatedDetents which accesses layoutState.get
|
|
164
|
+
// during initialization, so we need to wait for Reanimated to be fully ready
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
// Use a combination of setTimeout and requestAnimationFrame
|
|
167
|
+
// to ensure Reanimated is fully initialized before rendering
|
|
168
|
+
let frameId: number;
|
|
169
|
+
const timer = setTimeout(() => {
|
|
170
|
+
// Use multiple animation frames to ensure Reanimated worklets are ready
|
|
171
|
+
frameId = requestAnimationFrame(() => {
|
|
172
|
+
requestAnimationFrame(() => {
|
|
173
|
+
setIsMounted(true);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}, 150); // Increased delay to ensure Reanimated is fully initialized
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
clearTimeout(timer);
|
|
180
|
+
if (frameId) {
|
|
181
|
+
cancelAnimationFrame(frameId);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}, []);
|
|
159
185
|
|
|
160
186
|
// Expose ref methods
|
|
161
187
|
React.useImperativeHandle(ref, () => ({
|
|
162
188
|
present: () => {
|
|
163
|
-
|
|
189
|
+
if (isMounted) {
|
|
190
|
+
modalRef.current?.present();
|
|
191
|
+
}
|
|
164
192
|
},
|
|
165
193
|
dismiss: () => {
|
|
166
|
-
|
|
194
|
+
if (isMounted) {
|
|
195
|
+
modalRef.current?.dismiss();
|
|
196
|
+
}
|
|
167
197
|
},
|
|
168
198
|
snapToIndex: (index: number) => {
|
|
169
|
-
|
|
199
|
+
if (isMounted) {
|
|
200
|
+
modalRef.current?.snapToIndex(index);
|
|
201
|
+
}
|
|
170
202
|
},
|
|
171
203
|
snapToPosition: (position: string | number) => {
|
|
172
|
-
|
|
204
|
+
if (isMounted) {
|
|
205
|
+
modalRef.current?.snapToPosition(position);
|
|
206
|
+
}
|
|
173
207
|
},
|
|
174
208
|
expand: () => {
|
|
175
|
-
|
|
209
|
+
if (isMounted) {
|
|
210
|
+
modalRef.current?.expand();
|
|
211
|
+
}
|
|
176
212
|
},
|
|
177
213
|
collapse: () => {
|
|
178
|
-
|
|
214
|
+
if (isMounted) {
|
|
215
|
+
modalRef.current?.collapse();
|
|
216
|
+
}
|
|
179
217
|
},
|
|
180
218
|
}));
|
|
181
219
|
|
|
@@ -234,6 +272,11 @@ export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModal
|
|
|
234
272
|
[onChange, onDismiss]
|
|
235
273
|
);
|
|
236
274
|
|
|
275
|
+
// Don't render until Reanimated is ready to prevent layoutState errors
|
|
276
|
+
if (!isMounted) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
|
|
237
280
|
return (
|
|
238
281
|
<GorhomBottomSheetModal
|
|
239
282
|
ref={modalRef}
|