import Storage from 'notes-core/api/index'; import React, {useEffect, useState} from 'react'; import {Platform, StatusBar, View, Text} from 'react-native'; import * as Animatable from 'react-native-animatable'; import {getColorScheme, WEIGHT, SIZE} from './src/common/common'; import {DialogManager} from './src/components/DialogManager'; import {Menu} from './src/components/Menu'; import {ModalMenu} from './src/components/ModalMenu'; import SideMenu from './src/components/SideMenu'; import {Toast} from './src/components/Toast'; import {useTracked} from './src/provider'; import {ACTIONS} from './src/provider/actions'; import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager'; import { eCloseFullscreenEditor, eCloseSideMenu, eDisableGestures, eDispatchAction, eEnableGestures, eOpenFullscreenEditor, eOpenSideMenu, } from './src/services/events'; import NavigationService, { AppContainer, } from './src/services/NavigationService'; import {DeviceDetectionService} from './src/utils/deviceDetection'; import StorageInterface from './src/utils/storage'; import {w} from './src/utils/utils'; import Editor from './src/views/Editor'; import Animated, {Easing} from 'react-native-reanimated'; export const DDS = new DeviceDetectionService(); export const db = new Storage(StorageInterface); let sideMenuRef; let editorRef; let outColors; const {color, Value, timing, interpolate} = Animated; const App = () => { const [state, dispatch] = useTracked(); const {colors, loading} = state; const [init, setInit] = useState(false); const [fullscreen, setFullscreen] = useState(false); const openSidebar = () => { DDS.isTab ? null : sideMenuRef.openMenu(true); }; const closeSidebar = () => { DDS.isTab ? null : sideMenuRef.openMenu(false); }; const disableGestures = () => { DDS.isTab ? null : sideMenuRef.setGestureEnabled(false); }; const enableGestures = () => { DDS.isTab ? null : sideMenuRef.setGestureEnabled(true); }; const showFullScreenEditor = () => { setFullscreen(true); editorRef.setNativeProps({ style: { position: 'absolute', width: '100%', zIndex: 999, paddingHorizontal: 100, backgroundColor: outColors.bg, }, }); }; useEffect(() => { outColors = colors; }, [colors]); const closeFullScreenEditor = () => { setFullscreen(false); editorRef.setNativeProps({ style: { position: 'relative', width: '68%', zIndex: null, paddingHorizontal: 0, backgroundColor: 'transparent', }, }); }; useEffect(() => { eSubscribeEvent(eDispatchAction, type => { dispatch(type); }); return () => { eUnSubscribeEvent(eDispatchAction, type => { dispatch(type); }); }; }, []); useEffect(() => { eSubscribeEvent(eOpenSideMenu, openSidebar); eSubscribeEvent(eCloseSideMenu, closeSidebar); eSubscribeEvent(eDisableGestures, disableGestures); eSubscribeEvent(eEnableGestures, enableGestures); eSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor); eSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor); return () => { eUnSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor); eUnSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor); eUnSubscribeEvent(eOpenSideMenu, openSidebar); eUnSubscribeEvent(eCloseSideMenu, closeSidebar); eUnSubscribeEvent(eDisableGestures, disableGestures); eUnSubscribeEvent(eEnableGestures, enableGestures); }; }, []); useEffect(() => { if (Platform.OS === 'android') { StatusBar.setBackgroundColor('transparent'); StatusBar.setTranslucent(true); StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content'); } }, []); useEffect(() => { updateAppTheme().then(() => { db.init().then(async () => { let user = await db.user.get(); dispatch({type: ACTIONS.USER, user: user}); setInit(true); }); }); }, []); async function updateAppTheme(colors = colors) { let newColors = await getColorScheme(colors); dispatch({type: ACTIONS.THEME, colors: newColors}); } if (!init) { return <>; } return ( <> notes A safe plac nook e to write {DDS.isTab ? ( <> { //setSidebar('0%'); }} /> { NavigationService.setTopLevelNavigator(navigatorRef); }} /> (editorRef = ref)} style={{ width: '68%', height: '100%', backgroundColor: 'transparent', }}> ) : ( (sideMenuRef = ref)} bounceBackOnOverdraw={false} contentContainerStyle={{ opacity: 0, backgroundColor: colors.bg, }} menu={ sideMenuRef.openMenu(!sideMenuRef.isOpen)} /> } openMenuOffset={w / 1.5}> { NavigationService.setTopLevelNavigator(navigatorRef); }} /> )} ); }; export default App;