Fix dialogs state references, fixes Android back button (#3314)
* Fix active/open dialogs state * Improve close logic
This commit is contained in:
parent
55fb81867b
commit
eb0ee6ae1c
1 changed files with 8 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {SharedValue, useSharedValue} from 'react-native-reanimated'
|
import {SharedValue, useSharedValue} from 'react-native-reanimated'
|
||||||
|
|
||||||
import {DialogControlRefProps} from '#/components/Dialog'
|
import {DialogControlRefProps} from '#/components/Dialog'
|
||||||
import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
|
import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
|
||||||
|
|
||||||
|
@ -53,7 +54,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
>('auto')
|
>('auto')
|
||||||
|
|
||||||
const closeAllDialogs = React.useCallback(() => {
|
const closeAllDialogs = React.useCallback(() => {
|
||||||
activeDialogs.current.forEach(dialog => dialog.current.close())
|
openDialogs.current.forEach(id => {
|
||||||
|
const dialog = activeDialogs.current.get(id)
|
||||||
|
if (dialog) dialog.current.close()
|
||||||
|
})
|
||||||
return openDialogs.current.size > 0
|
return openDialogs.current.size > 0
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
@ -74,15 +78,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
|
||||||
const context = React.useMemo<IDialogContext>(
|
const context = React.useMemo<IDialogContext>(
|
||||||
() => ({
|
() => ({
|
||||||
activeDialogs: {
|
activeDialogs,
|
||||||
current: new Map(),
|
openDialogs,
|
||||||
},
|
|
||||||
openDialogs: {
|
|
||||||
current: new Set(),
|
|
||||||
},
|
|
||||||
importantForAccessibility,
|
importantForAccessibility,
|
||||||
}),
|
}),
|
||||||
[importantForAccessibility],
|
[importantForAccessibility, activeDialogs, openDialogs],
|
||||||
)
|
)
|
||||||
const controls = React.useMemo(
|
const controls = React.useMemo(
|
||||||
() => ({closeAllDialogs, setDialogIsOpen}),
|
() => ({closeAllDialogs, setDialogIsOpen}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue