Compare commits

...

1 Commits

Author SHA1 Message Date
Ammar Ahmed
65d2349993 mobile: fix dialog context on iOS 2026-03-13 10:40:23 +05:00
4 changed files with 36 additions and 4 deletions

View File

@@ -23,7 +23,6 @@ import {
ColorValue,
KeyboardAvoidingView,
Modal,
Platform,
SafeAreaView,
StyleSheet,
TouchableOpacity,
@@ -33,6 +32,7 @@ import useIsFloatingKeyboard from "../../hooks/use-is-floating-keyboard";
import { useSettingStore } from "../../stores/use-setting-store";
import { useUserStore } from "../../stores/use-user-store";
import { BouncingView } from "../ui/transitions/bouncing-view";
import { DIALOG_CONTEXT_STATE } from "./functions";
export interface BaseDialogProps extends PropsWithChildren {
animation?: "fade" | "none" | "slide" | undefined;
@@ -51,6 +51,7 @@ export interface BaseDialogProps extends PropsWithChildren {
useSafeArea?: boolean;
avoidKeyboardResize?: boolean;
enableSheetKeyboardHandler?: boolean;
context?: string;
}
const BaseDialog = ({
@@ -70,12 +71,14 @@ const BaseDialog = ({
useSafeArea = true,
avoidKeyboardResize = false,
enableSheetKeyboardHandler,
background
background,
context = "global"
}: BaseDialogProps) => {
const floating = useIsFloatingKeyboard();
const lockEvents = useRef(false);
const [internalVisible, setIntervalVisible] = useState(true);
const locked = useUserStore((state) => state.appLocked);
const reslover = useRef<(value?: any) => void>(undefined);
useEffect(() => {
return () => {
@@ -99,6 +102,15 @@ const BaseDialog = ({
}
}, [locked]);
useEffect(() => {
return () => {
setTimeout(() => {
reslover.current?.();
delete DIALOG_CONTEXT_STATE[context];
}, 1500);
};
}, []);
const Wrapper = useSafeArea ? SafeAreaView : View;
return (
@@ -122,9 +134,13 @@ const BaseDialog = ({
useSettingStore.getState().setSheetKeyboardHandler(false);
}
}
DIALOG_CONTEXT_STATE[context] = new Promise((resolve) => {
reslover.current = resolve;
});
}}
animationType={animation}
onRequestClose={() => {
onRequestClose={(e) => {
if (lockEvents.current) return;
if (!closeOnTouch) return null;
useSettingStore.getState().setSheetKeyboardHandler(true);

View File

@@ -70,3 +70,13 @@ export function presentDialog(data: Partial<DialogInfo>): void {
export function hideDialog(): void {
eSendEvent(eCloseSimpleDialog);
}
export const DIALOG_CONTEXT_STATE: Record<string, Promise<void>> = {};
export async function awaitDialogIfOpen(context = "global") {
if (context in DIALOG_CONTEXT_STATE) {
await DIALOG_CONTEXT_STATE[context];
return;
}
return;
}

View File

@@ -134,6 +134,7 @@ export const Dialog = ({ context = "global" }: { context?: string }) => {
? false
: dialogInfo.statusBarTranslucent
}
context={context}
bounce={!dialogInfo.input}
closeOnTouch={!dialogInfo.disableBackdropClosing}
background={dialogInfo.background}

View File

@@ -38,7 +38,10 @@ import { DatabaseLogger, db } from "../../../common/database";
import filesystem from "../../../common/filesystem";
import { deleteCacheFileByName } from "../../../common/filesystem/io";
import { cacheDir, copyFileAsync } from "../../../common/filesystem/utils";
import { presentDialog } from "../../../components/dialog/functions";
import {
awaitDialogIfOpen,
presentDialog
} from "../../../components/dialog/functions";
import {
endProgress,
startProgress,
@@ -106,6 +109,8 @@ const restoreBackup = async (options: {
const isLegacyBackup = options.uri.endsWith(".nnbackup");
await awaitDialogIfOpen();
startProgress({
title: strings.restoring(),
paragraph: strings.preparingBackupRestore(),