Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mobile: fix selecting image from gallery when applock is on #7332

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions apps/mobile/app/components/dialog/base-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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;

Expand Down
32 changes: 15 additions & 17 deletions apps/mobile/app/components/ui/sheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -99,24 +100,21 @@ const SheetWrapper = ({
};

useEffect(() => {
if (useUserStore.getState().disableAppLockRequests) return;
if (SettingsService.canLockAppInBackground()) {
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">
Expand Down
11 changes: 11 additions & 0 deletions apps/mobile/app/screens/editor/tiptap/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { eCloseSheet } from "../../../utils/events";
import { useTabStore } from "./use-tab-store";
import { editorController, editorState } from "./utils";
import { strings } from "@notesnook/intl";
import { useUserStore } from "../../../stores/use-user-store";
import { sleep } from "../../../utils/time";

const showEncryptionSheet = (file: DocumentPickerResponse) => {
presentSheet({
Expand Down Expand Up @@ -241,6 +243,13 @@ const gallery = async (options: PickerOptions) => {
const pick = async (options: PickerOptions) => {
if (!PremiumService.get()) {
const user = await db.user.getUser();
if (!user) {
ToastManager.show({
heading: strings.loginRequired(),
type: "error"
});
return;
}
if (editorState().isFocused) {
editorState().isFocused = true;
}
Expand All @@ -251,6 +260,7 @@ const pick = async (options: PickerOptions) => {
}
return;
}
useUserStore.getState().setDisableAppLockRequests(true);
if (options?.type.startsWith("image") || options?.type === "camera") {
if (options.type.startsWith("image")) {
gallery(options);
Expand All @@ -267,6 +277,7 @@ const handleImageResponse = async (
options: PickerOptions
) => {
const result = await AttachImage.present(response, options.context);

if (!result) return;
const compress = result.compress;

Expand Down
Loading