@attio/react-native-bottom-sheet-toolbox
Version:
20 lines (16 loc) • 700 B
text/typescript
import {useAnimatedReaction} from "react-native-reanimated"
import {useBottomSheetToolboxInternalContext} from "../context"
import {useBottomSheetActions} from "./use-bottom-sheet-actions"
export function useBottomSheetOpenWhenReady(initialSnapPointIndex: number) {
const {isReadySharedValue} = useBottomSheetToolboxInternalContext()
const {snapToIndex} = useBottomSheetActions("useBottomSheetOpenWhenReady")
useAnimatedReaction(
() => isReadySharedValue.get(),
(ready, lastReady) => {
if (!lastReady && ready && initialSnapPointIndex !== 0) {
snapToIndex(initialSnapPointIndex)
}
},
[isReadySharedValue]
)
}