remove a bunch of to-be-useless stuff
This commit is contained in:
@@ -1,24 +1,13 @@
|
|||||||
import React, {useImperativeHandle} from 'react'
|
import React, {useImperativeHandle} from 'react'
|
||||||
import {
|
import {Dimensions, Keyboard, StyleProp, View, ViewStyle} from 'react-native'
|
||||||
Dimensions,
|
|
||||||
Keyboard,
|
|
||||||
Pressable,
|
|
||||||
StyleProp,
|
|
||||||
View,
|
|
||||||
ViewStyle,
|
|
||||||
} from 'react-native'
|
|
||||||
import Animated, {useAnimatedStyle} from 'react-native-reanimated'
|
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import BottomSheet, {
|
import BottomSheet, {
|
||||||
BottomSheetBackdropProps,
|
|
||||||
BottomSheetFlatList,
|
BottomSheetFlatList,
|
||||||
BottomSheetFlatListMethods,
|
BottomSheetFlatListMethods,
|
||||||
BottomSheetScrollView,
|
BottomSheetScrollView,
|
||||||
BottomSheetScrollViewMethods,
|
BottomSheetScrollViewMethods,
|
||||||
BottomSheetTextInput,
|
BottomSheetTextInput,
|
||||||
BottomSheetView,
|
BottomSheetView,
|
||||||
useBottomSheet,
|
|
||||||
WINDOW_HEIGHT,
|
|
||||||
} from '@discord/bottom-sheet/src'
|
} from '@discord/bottom-sheet/src'
|
||||||
import {BottomSheetFlatListProps} from '@discord/bottom-sheet/src/components/bottomSheetScrollable/types'
|
import {BottomSheetFlatListProps} from '@discord/bottom-sheet/src/components/bottomSheetScrollable/types'
|
||||||
|
|
||||||
@@ -41,71 +30,20 @@ export * from '#/components/Dialog/utils'
|
|||||||
// @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,
|
||||||
onClose,
|
onClose,
|
||||||
nativeOptions,
|
nativeOptions: _nativeOptions, // @TODO DIALOG REFACTOR
|
||||||
testID,
|
testID,
|
||||||
}: React.PropsWithChildren<DialogOuterProps>) {
|
}: React.PropsWithChildren<DialogOuterProps>) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const sheet = React.useRef<BottomSheet>(null)
|
const sheet = React.useRef<BottomSheet>(null)
|
||||||
const sheetOptions = nativeOptions?.sheet || {}
|
|
||||||
const hasSnapPoints = !!sheetOptions.snapPoints
|
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const closeCallbacks = React.useRef<(() => void)[]>([])
|
const closeCallbacks = React.useRef<(() => void)[]>([])
|
||||||
const {setDialogIsOpen} = useDialogStateControlContext()
|
const {setDialogIsOpen} = useDialogStateControlContext()
|
||||||
|
// @TODO DIALOG REFACTOR - can i get rid of this? seems pointless tbh
|
||||||
/*
|
const [isOpen, setIsOpen] = React.useState(false)
|
||||||
* Used to manage open/closed, but index is otherwise handled internally by `BottomSheet`
|
|
||||||
*/
|
|
||||||
const [openIndex, setOpenIndex] = React.useState(-1)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* `openIndex` is the index of the snap point to open the bottom sheet to. If >0, the bottom sheet is open.
|
|
||||||
*/
|
|
||||||
const isOpen = openIndex > -1
|
|
||||||
|
|
||||||
const callQueuedCallbacks = React.useCallback(() => {
|
const callQueuedCallbacks = React.useCallback(() => {
|
||||||
for (const cb of closeCallbacks.current) {
|
for (const cb of closeCallbacks.current) {
|
||||||
@@ -119,25 +57,21 @@ export function Outer({
|
|||||||
closeCallbacks.current = []
|
closeCallbacks.current = []
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const open = React.useCallback<DialogControlProps['open']>(
|
const open = React.useCallback<DialogControlProps['open']>(() => {
|
||||||
({index} = {}) => {
|
// Run any leftover callbacks that might have been queued up before calling `.open()`
|
||||||
// Run any leftover callbacks that might have been queued up before calling `.open()`
|
callQueuedCallbacks()
|
||||||
callQueuedCallbacks()
|
setIsOpen(true)
|
||||||
|
setDialogIsOpen(control.id, true)
|
||||||
setDialogIsOpen(control.id, true)
|
// sheet.current?.open() // @TODO DIALOG REFACTOR
|
||||||
// can be set to any index of `snapPoints`, but `0` is the first i.e. "open"
|
}, [setDialogIsOpen, control.id, callQueuedCallbacks])
|
||||||
setOpenIndex(index || 0)
|
|
||||||
sheet.current?.snapToIndex(index || 0)
|
|
||||||
},
|
|
||||||
[setDialogIsOpen, control.id, callQueuedCallbacks],
|
|
||||||
)
|
|
||||||
|
|
||||||
// This is the function that we call when we want to dismiss the dialog.
|
// This is the function that we call when we want to dismiss the dialog.
|
||||||
const close = React.useCallback<DialogControlProps['close']>(cb => {
|
const close = React.useCallback<DialogControlProps['close']>(cb => {
|
||||||
|
setIsOpen(false)
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
closeCallbacks.current.push(cb)
|
closeCallbacks.current.push(cb)
|
||||||
}
|
}
|
||||||
sheet.current?.close()
|
// sheet.current?.close() // @TODO DIALOG REFACTOR
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// This is the actual thing we are doing once we "confirm" the dialog. We want the dialog's close animation to
|
// This is the actual thing we are doing once we "confirm" the dialog. We want the dialog's close animation to
|
||||||
@@ -146,8 +80,6 @@ export function Outer({
|
|||||||
// This removes the dialog from our list of stored dialogs. Not super necessary on iOS, but on Android this
|
// This removes the dialog from our list of stored dialogs. Not super necessary on iOS, but on Android this
|
||||||
// tells us that we need to toggle the accessibility overlay setting
|
// tells us that we need to toggle the accessibility overlay setting
|
||||||
setDialogIsOpen(control.id, false)
|
setDialogIsOpen(control.id, false)
|
||||||
setOpenIndex(-1)
|
|
||||||
|
|
||||||
callQueuedCallbacks()
|
callQueuedCallbacks()
|
||||||
onClose?.()
|
onClose?.()
|
||||||
}, [callQueuedCallbacks, control.id, onClose, setDialogIsOpen])
|
}, [callQueuedCallbacks, control.id, onClose, setDialogIsOpen])
|
||||||
@@ -180,18 +112,13 @@ export function Outer({
|
|||||||
testID={testID}
|
testID={testID}
|
||||||
onTouchMove={() => Keyboard.dismiss()}>
|
onTouchMove={() => Keyboard.dismiss()}>
|
||||||
<BottomSheet
|
<BottomSheet
|
||||||
enableDynamicSizing={!hasSnapPoints}
|
|
||||||
enablePanDownToClose
|
enablePanDownToClose
|
||||||
keyboardBehavior="interactive"
|
keyboardBehavior="interactive"
|
||||||
android_keyboardInputMode="adjustResize"
|
android_keyboardInputMode="adjustResize"
|
||||||
keyboardBlurBehavior="restore"
|
keyboardBlurBehavior="restore"
|
||||||
topInset={insets.top}
|
topInset={insets.top}
|
||||||
{...sheetOptions}
|
|
||||||
snapPoints={sheetOptions.snapPoints || ['100%']}
|
|
||||||
ref={sheet}
|
ref={sheet}
|
||||||
index={openIndex}
|
|
||||||
backgroundStyle={{backgroundColor: 'transparent'}}
|
backgroundStyle={{backgroundColor: 'transparent'}}
|
||||||
backdropComponent={Backdrop}
|
|
||||||
handleIndicatorStyle={{backgroundColor: t.palette.primary_500}}
|
handleIndicatorStyle={{backgroundColor: t.palette.primary_500}}
|
||||||
handleStyle={{display: 'none'}}
|
handleStyle={{display: 'none'}}
|
||||||
onClose={onCloseAnimationComplete}>
|
onClose={onCloseAnimationComplete}>
|
||||||
|
|||||||
Reference in New Issue
Block a user