Skip to content

Commit 0e01b3d

Browse files
committed
fix: sync up changes
1 parent 7778b04 commit 0e01b3d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

package/src/hooks/useAttachmentPickerBottomSheet.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useEffect, useRef } from 'react';
22

33
import BottomSheet from '@gorhom/bottom-sheet';
4+
import { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
45

56
/**
67
* This hook is used to manage the state of the attachment picker bottom sheet.
@@ -26,36 +27,36 @@ export const useAttachmentPickerBottomSheet = () => {
2627
[],
2728
);
2829

29-
const openPicker = useCallback(() => {
30+
const openPicker = useCallback((ref: React.RefObject<BottomSheetMethods | null>) => {
3031
if (bottomSheetCloseTimeoutRef.current) {
3132
clearTimeout(bottomSheetCloseTimeoutRef.current);
3233
}
33-
if (bottomSheetRef.current?.snapToIndex) {
34-
bottomSheetRef.current.snapToIndex(0);
34+
if (ref.current?.snapToIndex) {
35+
ref.current.snapToIndex(0);
3536
} else {
3637
console.warn('bottom and top insets must be set for the image picker to work correctly');
3738
}
3839
}, []);
3940

40-
const closePicker = useCallback(() => {
41-
if (bottomSheetRef.current?.close) {
41+
const closePicker = useCallback((ref: React.RefObject<BottomSheetMethods | null>) => {
42+
if (ref.current?.close) {
4243
if (bottomSheetCloseTimeoutRef.current) {
4344
clearTimeout(bottomSheetCloseTimeoutRef.current);
4445
}
45-
bottomSheetRef.current.close();
46+
ref.current.close();
4647
// Attempt to close the bottomsheet again to circumvent accidental opening on Android.
4748
// Details: This to prevent a race condition where the close function is called during the point when a internal container layout happens within the bottomsheet due to keyboard affecting the layout
4849
// If the container layout measures a shorter height than previous but if the close snapped to the previous height's position, the bottom sheet will show up
4950
// this short delay ensures that close function is always called after a container layout due to keyboard change
5051
// NOTE: this timeout has to be above 500 as the keyboardAnimationDuration is 500 in the bottomsheet library - see src/hooks/useKeyboard.ts there for more details
5152
bottomSheetCloseTimeoutRef.current = setTimeout(() => {
52-
bottomSheetRef.current?.close();
53+
ref.current?.close();
5354
}, 600);
5455
}
5556
}, []);
5657

5758
useEffect(() => {
58-
closePicker();
59+
closePicker(bottomSheetRef);
5960
}, [closePicker]);
6061

6162
return {

0 commit comments

Comments
 (0)