Clean up
This commit is contained in:
@@ -4,13 +4,14 @@ import {FocusScope} from '@tamagui/focus-scope'
|
|||||||
import Animated, {FadeInDown, FadeIn, FadeOut} from 'react-native-reanimated'
|
import Animated, {FadeInDown, FadeIn, FadeOut} from 'react-native-reanimated'
|
||||||
|
|
||||||
import {useTheme, atoms as a, useBreakpoints} from '#/alf'
|
import {useTheme, atoms as a, useBreakpoints} from '#/alf'
|
||||||
import {EventStopper} from '#/view/com/util/EventStopper'
|
|
||||||
import {Text} from '#/view/com/Typography'
|
import {Text} from '#/view/com/Typography'
|
||||||
import {Portal} from '#/view/com/Portal'
|
import {Portal} from '#/view/com/Portal'
|
||||||
import {Button} from '#/view/com/Button'
|
import {Button} from '#/view/com/Button'
|
||||||
|
|
||||||
import {DialogProps, DialogControl} from '#/view/com/Dialog/types'
|
import {DialogProps, DialogControl} from '#/view/com/Dialog/types'
|
||||||
|
|
||||||
|
const stopPropagation = (e: any) => e.stopPropagation()
|
||||||
|
|
||||||
const Context = React.createContext<{
|
const Context = React.createContext<{
|
||||||
close: () => void
|
close: () => void
|
||||||
}>({
|
}>({
|
||||||
@@ -58,6 +59,8 @@ export function Outer({
|
|||||||
)
|
)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (!isOpen) return
|
||||||
|
|
||||||
function handler(e: KeyboardEvent) {
|
function handler(e: KeyboardEvent) {
|
||||||
if (e.key === 'Escape') close()
|
if (e.key === 'Escape') close()
|
||||||
}
|
}
|
||||||
@@ -65,7 +68,7 @@ export function Outer({
|
|||||||
document.addEventListener('keydown', handler)
|
document.addEventListener('keydown', handler)
|
||||||
|
|
||||||
return () => document.removeEventListener('keydown', handler)
|
return () => document.removeEventListener('keydown', handler)
|
||||||
}, [close])
|
}, [isOpen, close])
|
||||||
|
|
||||||
const context = React.useMemo(() => ({close}), [close])
|
const context = React.useMemo(() => ({close}), [close])
|
||||||
|
|
||||||
@@ -105,14 +108,20 @@ export function Outer({
|
|||||||
paddingTop: gtMobile ? ('10vh' as DimensionValue) : 0,
|
paddingTop: gtMobile ? ('10vh' as DimensionValue) : 0,
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
<FocusScope loop enabled trapped>
|
<View
|
||||||
<Animated.View
|
// @ts-ignore web only -prf
|
||||||
entering={FadeInDown.duration(200)}
|
onClick={stopPropagation}
|
||||||
exiting={FadeOut.duration(200)}
|
onStartShouldSetResponder={_ => true}
|
||||||
aria-role="dialog">
|
onTouchEnd={stopPropagation}>
|
||||||
<EventStopper>{children}</EventStopper>
|
<FocusScope loop enabled trapped>
|
||||||
</Animated.View>
|
<Animated.View
|
||||||
</FocusScope>
|
entering={FadeInDown}
|
||||||
|
exiting={FadeOut}
|
||||||
|
aria-role="dialog">
|
||||||
|
{children}
|
||||||
|
</Animated.View>
|
||||||
|
</FocusScope>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</TouchableWithoutFeedback>
|
</TouchableWithoutFeedback>
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ export function Provider(props: React.PropsWithChildren<{}>) {
|
|||||||
setOutlet(<>{Object.values(map.current)}</>)
|
setOutlet(<>{Object.values(map.current)}</>)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
console.log(outlet)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Context.Provider value={{outlet, append, remove}}>
|
<Context.Provider value={{outlet, append, remove}}>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|||||||
@@ -334,15 +334,24 @@ function Dialogs() {
|
|||||||
<Dialog.Outer control={control}>
|
<Dialog.Outer control={control}>
|
||||||
<Dialog.Inner>
|
<Dialog.Inner>
|
||||||
<Dialog.Handle />
|
<Dialog.Handle />
|
||||||
<Dialog.Close />
|
<View style={[a.gap_md]}>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
size="small"
|
size="small"
|
||||||
onPress={() => control.current.close()}
|
onPress={() => control.current.close()}
|
||||||
accessibilityLabel="Open basic dialog"
|
accessibilityLabel="Open basic dialog"
|
||||||
accessibilityHint="Open basic dialog">
|
accessibilityHint="Open basic dialog">
|
||||||
Close basic dialog
|
Close basic dialog
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="secondary"
|
||||||
|
size="small"
|
||||||
|
onPress={() => control.current.close()}
|
||||||
|
accessibilityLabel="Open basic dialog"
|
||||||
|
accessibilityHint="Open basic dialog">
|
||||||
|
Some other control
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
</Dialog.Inner>
|
</Dialog.Inner>
|
||||||
</Dialog.Outer>
|
</Dialog.Outer>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user