From 0cd3bd57390a3d8109af6494507d98ad51993a87 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 11 Feb 2025 10:24:25 +0500 Subject: [PATCH] mobile: fix dialog calling onClose after pressing positive button --- apps/mobile/app/components/dialog/index.js | 13 +++++++------ apps/mobile/app/screens/settings/section-item.tsx | 7 +++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/mobile/app/components/dialog/index.js b/apps/mobile/app/components/dialog/index.js index 1a36c035dc..1549f93d67 100644 --- a/apps/mobile/app/components/dialog/index.js +++ b/apps/mobile/app/components/dialog/index.js @@ -80,8 +80,9 @@ export const Dialog = ({ context = "global" }) => { return; } } - - hide(); + setChecked(false); + values.current.inputValue = undefined; + setVisible(false); }; const show = useCallback( @@ -104,14 +105,14 @@ export const Dialog = ({ context = "global" }) => { eUnSubscribeEvent(eOpenSimpleDialog, show); eUnSubscribeEvent(eCloseSimpleDialog, hide); }; - }, [show]); + }, [hide, show]); - const hide = () => { + const hide = React.useCallback(() => { setChecked(false); values.current.inputValue = undefined; setVisible(false); - dialogInfo.onClose(); - }; + dialogInfo.onClose?.(); + }, [dialogInfo]); const onNegativePress = async () => { if (dialogInfo.onClose) { diff --git a/apps/mobile/app/screens/settings/section-item.tsx b/apps/mobile/app/screens/settings/section-item.tsx index 1aa1895ada..fabe2d1bf4 100644 --- a/apps/mobile/app/screens/settings/section-item.tsx +++ b/apps/mobile/app/screens/settings/section-item.tsx @@ -41,7 +41,10 @@ import { RouteParams, SettingSection } from "./types"; const _SectionItem = ({ item }: { item: SettingSection }) => { const { colors } = useThemeColors(); - const settings = useSettingStore((state) => state.settings); + const [settings, itemProperty] = useSettingStore((state) => [ + state.settings, + item.property ? state.settings[item.property] : null + ]); const navigation = useNavigation>(); const current = item.useHook && item.useHook(item); const [isHidden, setIsHidden] = useState( @@ -106,7 +109,7 @@ const _SectionItem = ({ item }: { item: SettingSection }) => { useEffect(() => { setIsHidden(item.hidden && item.hidden(item.property || current)); setIsDisabled(item.disabled && item.disabled(item.property || current)); - }, [current, item]); + }, [current, item, itemProperty]); return isHidden ? null : (