verdnatura-chat/app/lib/hooks/useSnaps.ts

15 lines
702 B
TypeScript
Raw Normal View History

2023-03-07 19:36:12 +00:00
import { useWindowDimensions } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
// Not sure if it's worth adding this here in the context of the actionSheet
/**
* Return the snaps based on the size you pass (aka: Size of action sheet)
* @param {Number[]} snaps Sizes you want to pass, pass only one if you want the action sheet to start at a specific size
*/
export const useSnaps = (snaps: number[]): string[] => {
const insets = useSafeAreaInsets();
2023-03-07 19:36:12 +00:00
const { height, scale } = useWindowDimensions();
const percentage = insets.bottom + insets.top > 75 ? 110 : 100;
2023-03-07 19:36:12 +00:00
return snaps.map(snap => `${((percentage * snap) / (height * scale)).toFixed(2)}%`);
};