-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathuseAttachmentPickerBottomSheet.ts
More file actions
35 lines (30 loc) · 1.26 KB
/
useAttachmentPickerBottomSheet.ts
File metadata and controls
35 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useCallback, useRef } from 'react';
import BottomSheet from '@gorhom/bottom-sheet';
import { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
/**
* This hook is used to manage the state of the attachment picker bottom sheet.
* It provides functions to open and close the bottom sheet, as well as a reference to the bottom sheet itself.
* The bottom sheet is used to display the attachment picker UI.
* The `openPicker` function opens the bottom sheet, and the `closePicker` function closes it.
* The `bottomSheetRef` is a reference to the bottom sheet component, which allows for programmatic control of the bottom sheet.
*/
export const useAttachmentPickerBottomSheet = () => {
const bottomSheetRef = useRef<BottomSheet>(null);
const openPicker = useCallback((ref: React.RefObject<BottomSheetMethods | null>) => {
if (ref.current?.snapToIndex) {
ref.current.snapToIndex(0);
} else {
console.warn('bottom and top insets must be set for the image picker to work correctly');
}
}, []);
const closePicker = useCallback((ref: React.RefObject<BottomSheetMethods | null>) => {
if (ref.current?.close) {
ref.current.close();
}
}, []);
return {
bottomSheetRef,
closePicker,
openPicker,
};
};