Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix lock state detection in sheets and dialogs

Ammar Ahmed92f5e04788de
diff --git a/apps/mobile/app/components/dialog/base-dialog.tsx b/apps/mobile/app/components/dialog/base-dialog.tsx
index 0ffa62fb4..a460cb9a9 100644
--- a/apps/mobile/app/components/dialog/base-dialog.tsx
+++ b/apps/mobile/app/components/dialog/base-dialog.tsx
@@ -75,9 +75,9 @@ const BaseDialog = ({
background
}: BaseDialogProps) => {
const floating = useIsFloatingKeyboard();
- const appState = useAppState();
const lockEvents = useRef(false);
const [internalVisible, setIntervalVisible] = useState(true);
+ const locked = useUserStore((state) => state.appLocked);
useEffect(() => {
return () => {
@@ -86,26 +86,20 @@ const BaseDialog = ({
}, []);
useEffect(() => {
- if (useUserStore.getState().disableAppLockRequests) return;
-
- if (SettingsService.canLockAppInBackground()) {
- if (appState === "background") {
- setIntervalVisible(false);
- if (useUserStore.getState().appLocked) {
- lockEvents.current = true;
- const unsub = useUserStore.subscribe((state) => {
- if (!state.appLocked) {
- setIntervalVisible(true);
- unsub();
- setTimeout(() => {
- lockEvents.current = false;
- });
- }
+ if (locked) {
+ setIntervalVisible(false);
+ lockEvents.current = true;
+ const unsub = useUserStore.subscribe((state) => {
+ if (!state.appLocked) {
+ setIntervalVisible(true);
+ unsub();
+ setTimeout(() => {
+ lockEvents.current = false;
});
}
- }
+ });
}
- }, [appState]);
+ }, [locked]);
const Wrapper = useSafeArea ? SafeAreaView : View;
diff --git a/apps/mobile/app/components/ui/sheet/index.js b/apps/mobile/app/components/ui/sheet/index.js
index b1d33dedb..6da9f3e93 100644
--- a/apps/mobile/app/components/ui/sheet/index.js
+++ b/apps/mobile/app/components/ui/sheet/index.js
@@ -59,8 +59,9 @@ const SheetWrapper = ({
const smallTablet = deviceMode === "smallTablet";
const dimensions = useSettingStore((state) => state.dimensions);
const insets = useGlobalSafeAreaInsets();
- const appState = useAppState();
const lockEvents = useRef(false);
+ const locked = useUserStore((state) => state.appLocked);
+
let width = dimensions.width > 600 ? 600 : 500;
const style = React.useMemo(() => {
@@ -99,27 +100,21 @@ const SheetWrapper = ({
};
useEffect(() => {
- if (useUserStore.getState().disableAppLockRequests) return;
- if (
- SettingsService.canLockAppInBackground() &&
- SettingsService.shouldLockAppOnEnterForeground()
- ) {
- if (appState === "background") {
- const ref = fwdRef || localRef;
- ref?.current?.hide();
- if (useUserStore.getState().appLocked) {
- lockEvents.current = true;
- const unsub = useUserStore.subscribe((state) => {
- if (!state.appLocked) {
- ref?.current?.show();
- unsub();
- lockEvents.current = false;
- }
- });
- }
+ if (locked) {
+ const ref = fwdRef || localRef;
+ ref?.current?.hide();
+ if (useUserStore.getState().appLocked) {
+ lockEvents.current = true;
+ const unsub = useUserStore.subscribe((state) => {
+ if (!state.appLocked) {
+ ref?.current?.show();
+ unsub();
+ lockEvents.current = false;
+ }
+ });
}
}
- }, [appState, fwdRef]);
+ }, [locked, fwdRef]);
return (
<ScopedThemeProvider value="sheet">