/* This file is part of the Notesnook project (https://notesnook.com/) Copyright (C) 2023 Streetwriters (Private) Limited 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 . */ import React, { useEffect, useRef } from "react"; import { AppState, KeyboardAvoidingView, Platform, TextInput, View } from "react-native"; import Editor from "."; import { PremiumToast } from "../../components/premium/premium-toast"; import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets"; import useIsFloatingKeyboard from "../../hooks/use-is-floating-keyboard"; import useKeyboard from "../../hooks/use-keyboard"; import { DDS } from "../../services/device-detection"; import { useSettingStore } from "../../stores/use-setting-store"; import { useThemeColors } from "@notesnook/theme"; import { editorRef } from "../../utils/global-refs"; import { ProgressBar } from "./progress"; import { editorController, textInput } from "./tiptap/utils"; export const EditorWrapper = ({ width }) => { const { colors } = useThemeColors(); const { colors: toolBarColors } = useThemeColors("editorToolbar"); const deviceMode = useSettingStore((state) => state.deviceMode); const loading = false; const insets = useGlobalSafeAreaInsets(); const floating = useIsFloatingKeyboard(); const introCompleted = useSettingStore( (state) => state.settings.introCompleted ); const keyboard = useKeyboard(); const prevState = useRef(); const onAppStateChanged = async (state) => { if (!prevState.current) { prevState.current = state; return; } if (useSettingStore.getState().appDidEnterBackgroundForAction) return; if (state === "active") { editorController.current.onReady(); editorController.current.overlay(false); } else { prevState.current = state; } }; useEffect(() => { if (loading) return; let sub = AppState.addEventListener("change", onAppStateChanged); return () => { sub?.remove(); }; }, [loading]); const getMarginBottom = () => { const bottomInsets = Platform.OS === "android" ? 12 : insets.bottom + 16 || 14; if (!keyboard.keyboardShown) return bottomInsets / 1.5; if (Platform.isPad && !floating) return bottomInsets; if (Platform.OS === "ios") return bottomInsets / 1.5; return 0; }; const KeyboardAvoidingViewIOS = Platform.OS === "ios" ? KeyboardAvoidingView : View; return ( {loading || !introCompleted ? null : ( {/* */} )} ); };