Fix backdrop issues by using custom logic (#3072)
* use custom backdrop * use custom backdrop * org imports * rm logzio/stable
parent
f016cdbca9
commit
411061ea32
|
@ -1,12 +1,15 @@
|
||||||
import React, {useImperativeHandle} from 'react'
|
import React, {useImperativeHandle} from 'react'
|
||||||
import {View, Dimensions, Keyboard} from 'react-native'
|
import {View, Dimensions, Keyboard, Pressable} from 'react-native'
|
||||||
import BottomSheet, {
|
import BottomSheet, {
|
||||||
BottomSheetBackdrop,
|
BottomSheetBackdropProps,
|
||||||
BottomSheetScrollView,
|
BottomSheetScrollView,
|
||||||
BottomSheetTextInput,
|
BottomSheetTextInput,
|
||||||
BottomSheetView,
|
BottomSheetView,
|
||||||
|
useBottomSheet,
|
||||||
|
WINDOW_HEIGHT,
|
||||||
} from '@gorhom/bottom-sheet'
|
} from '@gorhom/bottom-sheet'
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
|
import Animated, {useAnimatedStyle} from 'react-native-reanimated'
|
||||||
|
|
||||||
import {useTheme, atoms as a, flatten} from '#/alf'
|
import {useTheme, atoms as a, flatten} from '#/alf'
|
||||||
import {Portal} from '#/components/Portal'
|
import {Portal} from '#/components/Portal'
|
||||||
|
@ -26,6 +29,47 @@ export * from '#/components/Dialog/types'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const Input = createInput(BottomSheetTextInput)
|
export const Input = createInput(BottomSheetTextInput)
|
||||||
|
|
||||||
|
function Backdrop(props: BottomSheetBackdropProps) {
|
||||||
|
const t = useTheme()
|
||||||
|
const bottomSheet = useBottomSheet()
|
||||||
|
|
||||||
|
const animatedStyle = useAnimatedStyle(() => {
|
||||||
|
const opacity =
|
||||||
|
(Math.abs(WINDOW_HEIGHT - props.animatedPosition.value) - 50) / 1000
|
||||||
|
|
||||||
|
return {
|
||||||
|
opacity: Math.min(Math.max(opacity, 0), 0.55),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const onPress = React.useCallback(() => {
|
||||||
|
bottomSheet.close()
|
||||||
|
}, [bottomSheet])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View
|
||||||
|
style={[
|
||||||
|
t.atoms.bg_contrast_300,
|
||||||
|
{
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
position: 'absolute',
|
||||||
|
},
|
||||||
|
animatedStyle,
|
||||||
|
]}>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Dialog backdrop"
|
||||||
|
accessibilityHint="Press the backdrop to close the dialog"
|
||||||
|
style={{flex: 1}}
|
||||||
|
onPress={onPress}
|
||||||
|
/>
|
||||||
|
</Animated.View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function Outer({
|
export function Outer({
|
||||||
children,
|
children,
|
||||||
control,
|
control,
|
||||||
|
@ -114,15 +158,7 @@ export function Outer({
|
||||||
ref={sheet}
|
ref={sheet}
|
||||||
index={openIndex}
|
index={openIndex}
|
||||||
backgroundStyle={{backgroundColor: 'transparent'}}
|
backgroundStyle={{backgroundColor: 'transparent'}}
|
||||||
backdropComponent={props => (
|
backdropComponent={Backdrop}
|
||||||
<BottomSheetBackdrop
|
|
||||||
opacity={0.4}
|
|
||||||
appearsOnIndex={0}
|
|
||||||
disappearsOnIndex={-1}
|
|
||||||
{...props}
|
|
||||||
style={[flatten(props.style), t.atoms.bg_contrast_300]}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
handleIndicatorStyle={{backgroundColor: t.palette.primary_500}}
|
handleIndicatorStyle={{backgroundColor: t.palette.primary_500}}
|
||||||
handleStyle={{display: 'none'}}
|
handleStyle={{display: 'none'}}
|
||||||
onChange={onChange}>
|
onChange={onChange}>
|
||||||
|
|
Loading…
Reference in New Issue