mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-05 09:49:10 +00:00
41 lines
No EOL
977 B
TypeScript
41 lines
No EOL
977 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
import { BackHandler } from 'react-native';
|
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
|
|
export function useBottomSheetBackHandler() {
|
|
const activeSheetRef =
|
|
useRef<React.RefObject<BottomSheetModal> | null>(null);
|
|
|
|
useEffect(() => {
|
|
const sub = BackHandler.addEventListener(
|
|
'hardwareBackPress',
|
|
() => {
|
|
if (activeSheetRef.current?.current) {
|
|
activeSheetRef.current.current.dismiss();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
);
|
|
|
|
return () => sub.remove();
|
|
}, []);
|
|
|
|
const onChange =
|
|
(ref: React.RefObject<BottomSheetModal>) =>
|
|
(index: number) => {
|
|
if (index >= 0) {
|
|
activeSheetRef.current = ref;
|
|
}
|
|
};
|
|
|
|
const onDismiss =
|
|
(ref: React.RefObject<BottomSheetModal>) => () => {
|
|
if (activeSheetRef.current === ref) {
|
|
activeSheetRef.current = null;
|
|
}
|
|
};
|
|
|
|
return { onChange, onDismiss };
|
|
} |