From 94d31d4cc50d567b6b237e147d0e453ff9964954 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 15 Jan 2024 10:48:59 -0600 Subject: [PATCH] Try to use BottomSheet's own APIs --- src/components/Dialog/index.tsx | 57 ++++++++++++-------------- src/view/screens/Storybook/Dialogs.tsx | 2 +- src/view/screens/Storybook/index.tsx | 2 +- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 7b3e34db20..de9d69edb2 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -1,6 +1,9 @@ import React, {useImperativeHandle} from 'react' -import {View, Dimensions, LayoutChangeEvent} from 'react-native' -import BottomSheet, {BottomSheetBackdrop} from '@gorhom/bottom-sheet' +import {View, Dimensions} from 'react-native' +import BottomSheet, { + BottomSheetBackdrop, + BottomSheetView, +} from '@gorhom/bottom-sheet' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useTheme, atoms as a} from '#/alf' @@ -29,12 +32,8 @@ export function Outer({ onClose, nativeOptions, }: React.PropsWithChildren) { - const insets = useSafeAreaInsets() const t = useTheme() const sheet = React.useRef(null) - const [defaultSnapPoints, setDefaultSnapPoints] = React.useState< - string | number - >('25%') const open = React.useCallback((i = 0) => { sheet.current?.snapToIndex(i) @@ -45,15 +44,6 @@ export function Outer({ onClose?.() }, [onClose]) - const measureDefaultSnapPoint = React.useCallback( - (e: LayoutChangeEvent) => { - const min = e.nativeEvent.layout.height + insets.bottom + 40 - const max = Dimensions.get('window').height - insets.top - 40 - setDefaultSnapPoints(min < max ? min : max) - }, - [insets, setDefaultSnapPoints], - ) - useImperativeHandle( control.ref, () => ({ @@ -68,10 +58,11 @@ export function Outer({ return ( - - - {children} - + + + + {children} + + ) @@ -108,6 +101,7 @@ export function Outer({ // TODO a11y props here, or is that handled by the sheet? export function Inner(props: DialogInnerProps) { + const insets = useSafeAreaInsets() return ( {props.children} diff --git a/src/view/screens/Storybook/Dialogs.tsx b/src/view/screens/Storybook/Dialogs.tsx index 8ecc2d101c..f34fca8b85 100644 --- a/src/view/screens/Storybook/Dialogs.tsx +++ b/src/view/screens/Storybook/Dialogs.tsx @@ -51,7 +51,7 @@ export function Dialogs() { accessibilityDescribedBy="dialog-description"> - +

Dialog

Description

diff --git a/src/view/screens/Storybook/index.tsx b/src/view/screens/Storybook/index.tsx index 4006c192b4..bde3b33b2a 100644 --- a/src/view/screens/Storybook/index.tsx +++ b/src/view/screens/Storybook/index.tsx @@ -53,6 +53,7 @@ export function Storybook() { + @@ -68,7 +69,6 @@ export function Storybook() { -