add dismiss all

This commit is contained in:
Hailey
2024-10-02 22:40:31 -07:00
parent a32f58753d
commit cc81342256
6 changed files with 17 additions and 13 deletions
+2 -2
View File
@@ -1,13 +1,13 @@
import {BottomSheet} from './src/BottomSheet'
import {
BottomSheetSnapPoint,
BottomSheetState,
BottomSheetViewProps,
} from './src/BottomSheet.types'
import {BottomSheetView} from './src/BottomSheetView'
export {
BottomSheet,
BottomSheetSnapPoint,
type BottomSheetState,
BottomSheetView,
type BottomSheetViewProps,
}
@@ -8,6 +8,7 @@ import {
View,
ViewStyle,
} from 'react-native'
import {requireNativeModule} from 'expo'
import {requireNativeViewManager} from 'expo-modules-core'
import {BottomSheetState, BottomSheetViewProps} from './BottomSheet.types'
@@ -21,7 +22,9 @@ const NativeView: React.ComponentType<
}
> = requireNativeViewManager('BottomSheet')
export class BottomSheetView extends React.Component<
const NativeModule = requireNativeModule('BottomSheet')
export class BottomSheet extends React.Component<
BottomSheetViewProps,
{
open: boolean
@@ -68,6 +71,10 @@ export class BottomSheetView extends React.Component<
this.ref.current?.updateLayout()
}
static dismissAll = async () => {
await NativeModule.dismissAll()
}
render() {
const {children, ...rest} = this.props
const topInset = rest.topInset ?? 0
@@ -1,5 +1,5 @@
import {BottomSheetViewProps} from './BottomSheet.types'
export function BottomSheetView(_: BottomSheetViewProps) {
export function BottomSheet(_: BottomSheetViewProps) {
throw new Error('BottomSheetView is not available on web')
}
+4 -7
View File
@@ -17,10 +17,7 @@ import {
} from '#/components/Dialog/types'
import {createInput} from '#/components/forms/TextField'
import {Portal as DefaultPortal} from '#/components/Portal'
import {
BottomSheetSnapPoint,
BottomSheetView,
} from '../../../modules/bottom-sheet'
import {BottomSheet, BottomSheetSnapPoint} from '../../../modules/bottom-sheet'
export {useDialogContext, useDialogControl} from '#/components/Dialog/context'
export * from '#/components/Dialog/types'
@@ -37,7 +34,7 @@ export function Outer({
Portal = DefaultPortal,
}: React.PropsWithChildren<DialogOuterProps>) {
const t = useTheme()
const ref = React.useRef<BottomSheetView>(null)
const ref = React.useRef<BottomSheet>(null)
const insets = useSafeAreaInsets()
const closeCallbacks = React.useRef<(() => void)[]>([])
const {setDialogIsOpen} = useDialogStateControlContext()
@@ -102,7 +99,7 @@ export function Outer({
return (
<Portal>
<Context.Provider value={context}>
<BottomSheetView
<BottomSheet
ref={ref}
topInset={30}
bottomInset={insets.bottom}
@@ -119,7 +116,7 @@ export function Outer({
<Wrapper testID={testID} style={[t.atoms.bg]}>
{children}
</Wrapper>
</BottomSheetView>
</BottomSheet>
</Context.Provider>
</Portal>
)
+2 -2
View File
@@ -3,6 +3,7 @@ import React from 'react'
import {isWeb} from '#/platform/detection'
import {DialogControlRefProps} from '#/components/Dialog'
import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
import {BottomSheet} from '../../../modules/bottom-sheet'
interface IDialogContext {
/**
@@ -51,8 +52,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
return openDialogs.current.size > 0
} else {
// @TODO DIALOGS REFACTOR
console.error('HAILEY FIX THIS 🥺📋')
BottomSheet.dismissAll()
return false
}
}, [])