2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
2023-01-16 13:44:52 +05:00
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
2022-08-31 06:33:37 +05:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-08-30 16:13:11 +05:00
|
|
|
|
2023-10-02 11:51:44 +05:00
|
|
|
import { ScopedThemeProvider, useThemeColors } from "@notesnook/theme";
|
|
|
|
|
import React, { useEffect, useRef } from "react";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { Platform, View } from "react-native";
|
|
|
|
|
import ActionSheet from "react-native-actions-sheet";
|
2022-09-07 12:43:35 +05:00
|
|
|
import useGlobalSafeAreaInsets from "../../../hooks/use-global-safe-area-insets";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { useSettingStore } from "../../../stores/use-setting-store";
|
|
|
|
|
import { PremiumToast } from "../../premium/premium-toast";
|
|
|
|
|
import { Toast } from "../../toast";
|
2023-10-02 11:51:44 +05:00
|
|
|
import { useAppState } from "../../../hooks/use-app-state";
|
|
|
|
|
import SettingsService from "../../../services/settings";
|
|
|
|
|
import { useUserStore } from "../../../stores/use-user-store";
|
2020-12-19 13:15:34 +05:00
|
|
|
|
2021-12-25 11:16:33 +05:00
|
|
|
const SheetWrapper = ({
|
2020-12-19 13:15:34 +05:00
|
|
|
children,
|
|
|
|
|
fwdRef,
|
2020-12-19 13:59:41 +05:00
|
|
|
gestureEnabled = true,
|
2020-12-19 13:15:34 +05:00
|
|
|
onClose,
|
|
|
|
|
onOpen,
|
2020-12-19 13:59:41 +05:00
|
|
|
closeOnTouchBackdrop = true,
|
2021-07-10 14:23:30 +05:00
|
|
|
onHasReachedTop,
|
2022-02-07 14:44:48 +05:00
|
|
|
overlay,
|
2023-03-16 21:22:21 +05:00
|
|
|
overlayOpacity = 0.3,
|
2023-03-23 23:31:06 +05:00
|
|
|
enableGesturesInScrollView = false,
|
2024-01-29 11:01:49 +05:00
|
|
|
bottomPadding = true,
|
|
|
|
|
keyboardHandlerDisabled
|
2020-12-19 13:15:34 +05:00
|
|
|
}) => {
|
2023-10-02 11:51:44 +05:00
|
|
|
const localRef = useRef(null);
|
2023-08-01 12:07:21 +05:00
|
|
|
const { colors } = useThemeColors("sheet");
|
2022-08-26 16:19:39 +05:00
|
|
|
const deviceMode = useSettingStore((state) => state.deviceMode);
|
|
|
|
|
const sheetKeyboardHandler = useSettingStore(
|
|
|
|
|
(state) => state.sheetKeyboardHandler
|
|
|
|
|
);
|
|
|
|
|
const largeTablet = deviceMode === "tablet";
|
|
|
|
|
const smallTablet = deviceMode === "smallTablet";
|
|
|
|
|
const dimensions = useSettingStore((state) => state.dimensions);
|
2022-09-07 12:43:35 +05:00
|
|
|
const insets = useGlobalSafeAreaInsets();
|
2023-10-02 11:51:44 +05:00
|
|
|
const appState = useAppState();
|
|
|
|
|
const lockEvents = useRef(false);
|
2021-07-24 11:02:45 +05:00
|
|
|
let width = dimensions.width > 600 ? 600 : 500;
|
|
|
|
|
|
2020-12-19 13:15:34 +05:00
|
|
|
const style = React.useMemo(() => {
|
|
|
|
|
return {
|
2022-08-26 16:19:39 +05:00
|
|
|
width: largeTablet || smallTablet ? width : "100%",
|
2023-08-01 12:07:21 +05:00
|
|
|
backgroundColor: colors.primary.background,
|
2020-12-19 13:15:34 +05:00
|
|
|
zIndex: 10,
|
2021-11-08 15:05:34 +05:00
|
|
|
paddingTop: 5,
|
2021-07-10 14:23:30 +05:00
|
|
|
paddingBottom: 0,
|
2023-03-16 21:22:21 +05:00
|
|
|
borderTopRightRadius: 15,
|
|
|
|
|
borderTopLeftRadius: 15,
|
2022-08-26 16:19:39 +05:00
|
|
|
alignSelf: "center",
|
2021-07-25 01:13:58 +05:00
|
|
|
borderBottomRightRadius: 0,
|
|
|
|
|
borderBottomLeftRadius: 0
|
2020-12-19 13:15:34 +05:00
|
|
|
};
|
2023-08-01 12:07:21 +05:00
|
|
|
}, [colors.primary.background, largeTablet, smallTablet, width]);
|
2020-12-19 13:15:34 +05:00
|
|
|
|
2021-02-15 11:02:09 +05:00
|
|
|
const _onOpen = () => {
|
2023-10-02 11:51:44 +05:00
|
|
|
if (lockEvents.current) return;
|
2021-02-15 11:02:09 +05:00
|
|
|
onOpen && onOpen();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const _onClose = async () => {
|
2023-10-02 11:51:44 +05:00
|
|
|
if (lockEvents.current) return;
|
2021-02-15 11:02:09 +05:00
|
|
|
if (onClose) {
|
|
|
|
|
onClose();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-02 11:51:44 +05:00
|
|
|
useEffect(() => {
|
2023-12-18 10:34:21 +05:00
|
|
|
if (useUserStore.getState().disableAppLockRequests) return;
|
2023-10-02 11:51:44 +05:00
|
|
|
if (SettingsService.get().appLockMode === "background") {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [appState, fwdRef]);
|
|
|
|
|
|
2020-12-19 13:15:34 +05:00
|
|
|
return (
|
2023-08-01 12:07:21 +05:00
|
|
|
<ScopedThemeProvider value="sheet">
|
|
|
|
|
<ActionSheet
|
2023-10-02 11:51:44 +05:00
|
|
|
ref={fwdRef || localRef}
|
2023-08-01 12:07:21 +05:00
|
|
|
testIDs={{
|
|
|
|
|
backdrop: "sheet-backdrop"
|
|
|
|
|
}}
|
|
|
|
|
indicatorStyle={{
|
|
|
|
|
width: 100,
|
|
|
|
|
backgroundColor: colors.secondary.background
|
|
|
|
|
}}
|
|
|
|
|
drawUnderStatusBar={false}
|
|
|
|
|
containerStyle={style}
|
|
|
|
|
gestureEnabled={gestureEnabled}
|
|
|
|
|
initialOffsetFromBottom={1}
|
|
|
|
|
onPositionChanged={onHasReachedTop}
|
|
|
|
|
closeOnTouchBackdrop={closeOnTouchBackdrop}
|
2024-01-29 11:01:49 +05:00
|
|
|
keyboardHandlerEnabled={
|
|
|
|
|
keyboardHandlerDisabled ? false : sheetKeyboardHandler
|
|
|
|
|
}
|
2023-08-01 12:07:21 +05:00
|
|
|
closeOnPressBack={closeOnTouchBackdrop}
|
|
|
|
|
indicatorColor={colors.secondary.background}
|
|
|
|
|
onOpen={_onOpen}
|
|
|
|
|
keyboardDismissMode="none"
|
|
|
|
|
enableGesturesInScrollView={enableGesturesInScrollView}
|
|
|
|
|
defaultOverlayOpacity={overlayOpacity}
|
|
|
|
|
overlayColor={colors.primary.backdrop}
|
|
|
|
|
keyboardShouldPersistTaps="always"
|
|
|
|
|
openAnimationConfig={{
|
|
|
|
|
friction: 9
|
|
|
|
|
}}
|
|
|
|
|
ExtraOverlayComponent={
|
|
|
|
|
<>
|
|
|
|
|
{overlay}
|
|
|
|
|
<PremiumToast
|
|
|
|
|
context="sheet"
|
|
|
|
|
close={() => fwdRef?.current?.hide()}
|
|
|
|
|
offset={50}
|
|
|
|
|
/>
|
|
|
|
|
<Toast context="local" />
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
onClose={_onClose}
|
|
|
|
|
>
|
2023-08-16 10:14:39 +05:00
|
|
|
{children}
|
|
|
|
|
{bottomPadding ? (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
height:
|
|
|
|
|
Platform.OS === "ios" && insets.bottom !== 0
|
|
|
|
|
? insets.bottom + 5
|
|
|
|
|
: 20
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2023-08-01 12:07:21 +05:00
|
|
|
</ActionSheet>
|
|
|
|
|
</ScopedThemeProvider>
|
2020-12-19 13:15:34 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-25 11:16:33 +05:00
|
|
|
export default SheetWrapper;
|