A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
refactor App.js
ammarahm-ed97e772911072
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 37fe5cf6d..2f3482b5e 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -1,72 +1,24 @@import React, {useEffect, useState} from 'react';-import {Platform, StatusBar, View} from 'react-native';import * as Animatable from 'react-native-animatable';+import MMKV from 'react-native-mmkv-storage';+import Orientation from 'react-native-orientation';+import {Loading} from './Loading';import {getColorScheme, scale, updateSize} 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 Orientation from 'react-native-orientation';-import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';-import {- eCloseFullscreenEditor,- eDispatchAction,- eOpenFullscreenEditor,-} from './src/services/events';-import NavigationService, {- AppContainer,-} from './src/services/NavigationService';-import {w, DDS, db} from './src/utils/utils';-import Editor from './src/views/Editor';-import Animated from 'react-native-reanimated';-import MMKV from 'react-native-mmkv-storage';import {defaultState} from './src/provider/defaultState';-import {EditorPosition} from './src/utils/animations';-import {sideMenuRef} from './src/utils/refs';-import {Loading} from './Loading';+import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';+import {eDispatchAction} from './src/services/events';+import {db, DDS} from './src/utils/utils';-let editorRef;-let outColors;+const I = DDS.isTab ? require('./index.tablet') : require('./index.mobile');const App = () => {const [state, dispatch] = useTracked();const {colors} = state;const [init, setInit] = useState(false);- const [fullscreen, setFullscreen] = useState(false);-- 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',- },- });- };const _onOrientationChange = o => {// Currently orientation is locked on tablet.@@ -91,26 +43,10 @@ const App = () => {useEffect(() => {DDS.isTab ? Orientation.lockToLandscape() : Orientation.lockToPortrait();-- eSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);- eSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);-- return () => {- eUnSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);- eUnSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);- };}, []);useEffect(() => {- if (Platform.OS === 'android') {- StatusBar.setBackgroundColor('transparent');- StatusBar.setTranslucent(true);- StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');- }- }, []);-- useEffect(() => {- updateAppTheme().then(() => {+ Initialize().then(() => {db.init().then(async () => {let user = await db.user.get();dispatch({type: ACTIONS.USER, user: user});@@ -120,7 +56,7 @@ const App = () => {});}, []);- async function updateAppTheme(colors = colors) {+ async function Initialize(colors = colors) {let newColors = await getColorScheme(colors);let s = await MMKV.getString('settings');if (typeof s !== 'string') {@@ -155,111 +91,8 @@ const App = () => {backgroundColor: colors.bg,}}><Loading />- {DDS.isTab ? (- <>- <ModalMenu colors={colors} />- <Animatable.View- animation="fadeIn"- useNativeDriver={true}- duration={500}- delay={450}- style={{- width: '4%',- }}>- <Menu- hide={false}- noTextMode={true}- colors={colors}- close={() => {- //setSidebar('0%');- }}- />- </Animatable.View>-- <Animatable.View- transition="backgroundColor"- duration={300}- style={{- width: '28%',- height: '100%',- borderRightColor: colors.nav,- borderRightWidth: 2,- }}>- <AppContainer- style={{- width: '100%',- height: '100%',- }}- ref={navigatorRef => {- NavigationService.setTopLevelNavigator(navigatorRef);- }}- />- </Animatable.View>-- <View- ref={ref => (editorRef = ref)}- style={{- width: '68%',- height: '100%',- backgroundColor: 'transparent',- }}>- <Editor noMenu={fullscreen ? false : true} />- </View>- </>- ) : (- <SideMenu- ref={sideMenuRef}- bounceBackOnOverdraw={false}- contentContainerStyle={{- opacity: 0,- backgroundColor: colors.bg,- }}- menu={- <Menu- hide={false}- colors={colors}- close={() =>- sideMenuRef.current?.openMenu(!sideMenuRef.current?.isOpen)- }- />- }- openMenuOffset={w / 1.5}>- <AppContainer- style={{- width: DDS.isTab ? '70%' : '100%',- height: '100%',- backgroundColor: colors.bg,- }}- ref={navigatorRef => {- NavigationService.setTopLevelNavigator(navigatorRef);- }}- />- </SideMenu>- )}-- <Animated.View- ref={ref => (editorRef = ref)}- onResponderTerminationRequest={true}- onStartShouldSetResponderCapture={false}- onStartShouldSetResponder={false}- onMoveShouldSetResponder={false}- onMoveShouldSetResponderCapture={false}- style={{- width: '100%',- height: '100%',- alignSelf: 'flex-end',- position: 'absolute',- backgroundColor: colors.bg,- elevation: 10,- transform: [- {- translateX: EditorPosition,- },- ],- }}>- <Editor noMenu={false} />- </Animated.View>+ <I.Initialize /><Toast />diff --git a/apps/mobile/index.mobile.js b/apps/mobile/index.mobile.jsnew file mode 100644index 000000000..fa450f506--- /dev/null+++ b/apps/mobile/index.mobile.js@@ -0,0 +1,83 @@+import React from 'react';+import Animated from 'react-native-reanimated';+import {Menu} from './src/components/Menu';+import SideMenu from './src/components/SideMenu';+import NavigationService, {+ AppContainer,+} from './src/services/NavigationService';+import {EditorPosition} from './src/utils/animations';+import {sideMenuRef} from './src/utils/refs';+import {DDS, w} from './src/utils/utils';+import Editor from './src/views/Editor';+import {useTracked} from './src/provider';+import {StatusBar, Platform} from 'react-native';++let editorRef;+export const Initialize = () => {+ const [state, dispatch] = useTracked();+ const {colors} = state;++ useEffect(() => {+ if (Platform.OS === 'android') {+ StatusBar.setBackgroundColor('transparent');+ StatusBar.setTranslucent(true);+ StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');+ }+ }, []);+ return (+ <>+ <SideMenu+ ref={sideMenuRef}+ bounceBackOnOverdraw={false}+ contentContainerStyle={{+ opacity: 0,+ backgroundColor: colors.bg,+ }}+ menu={+ <Menu+ hide={false}+ colors={colors}+ close={() =>+ sideMenuRef.current?.openMenu(!sideMenuRef.current?.isOpen)+ }+ />+ }+ openMenuOffset={w / 1.5}>+ <AppContainer+ style={{+ width: DDS.isTab ? '70%' : '100%',+ height: '100%',+ backgroundColor: colors.bg,+ }}+ ref={navigatorRef => {+ NavigationService.setTopLevelNavigator(navigatorRef);+ }}+ />+ </SideMenu>+ )}+ <Animated.View+ ref={ref => (editorRef = ref)}+ onResponderTerminationRequest={true}+ onStartShouldSetResponderCapture={false}+ onStartShouldSetResponder={false}+ onMoveShouldSetResponder={false}+ onMoveShouldSetResponderCapture={false}+ style={{+ width: '100%',+ height: '100%',+ alignSelf: 'flex-end',+ position: 'absolute',+ backgroundColor: colors.bg,+ elevation: 10,++ transform: [+ {+ translateX: EditorPosition,+ },+ ],+ }}>+ <Editor noMenu={false} />+ </Animated.View>+ </>+ );+};diff --git a/apps/mobile/index.tablet.js b/apps/mobile/index.tablet.jsnew file mode 100644index 000000000..3fc6e65f9--- /dev/null+++ b/apps/mobile/index.tablet.js@@ -0,0 +1,113 @@+import React from 'react';+import {View, Platform, StatusBar} from 'react-native';+import * as Animatable from 'react-native-animatable';+import {Menu} from './src/components/Menu';+import {ModalMenu} from './src/components/ModalMenu';+import NavigationService, {+ AppContainer,+} from './src/services/NavigationService';+import Editor from './src/views/Editor';+import {useTracked} from './src/provider';++let editorRef;+let outColors;++export const Initialize = () => {+ const [state, dispatch] = useTracked();+ const {colors} = state;++ const [fullscreen, setFullscreen] = useState(false);++ useEffect(() => {+ outColors = colors;+ }, [colors]);++ const showFullScreenEditor = () => {+ setFullscreen(true);++ editorRef.setNativeProps({+ style: {+ position: 'absolute',+ width: '100%',+ zIndex: 999,+ paddingHorizontal: 100,+ backgroundColor: outColors.bg,+ },+ });+ };++ const closeFullScreenEditor = () => {+ setFullscreen(false);+ editorRef.setNativeProps({+ style: {+ position: 'relative',+ width: '68%',+ zIndex: null,+ paddingHorizontal: 0,+ backgroundColor: 'transparent',+ },+ });+ };++ useEffect(() => {+ eSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);+ eSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);++ return () => {+ eUnSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);+ eUnSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);+ };+ }, []);++ useEffect(() => {+ if (Platform.OS === 'android') {+ StatusBar.setBackgroundColor('transparent');+ StatusBar.setTranslucent(true);+ StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');+ }+ }, []);++ return (+ <>+ <ModalMenu colors={colors} />+ <Animatable.View+ animation="fadeIn"+ useNativeDriver={true}+ duration={500}+ delay={450}+ style={{+ width: '4%',+ }}>+ <Menu hide={false} noTextMode={true} colors={colors} />+ </Animatable.View>+ <Animatable.View+ transition="backgroundColor"+ duration={300}+ style={{+ width: '28%',+ height: '100%',+ borderRightColor: colors.nav,+ borderRightWidth: 2,+ }}>+ <AppContainer+ style={{+ width: '100%',+ height: '100%',+ }}+ ref={navigatorRef => {+ NavigationService.setTopLevelNavigator(navigatorRef);+ }}+ />+ </Animatable.View>+ <View+ ref={ref => (editorRef = ref)}+ style={{+ width: '68%',+ height: '100%',+ backgroundColor: 'transparent',+ }}>+ <Editor noMenu={fullscreen ? false : true} />+ </View>+ </>+ );+};