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
control sideMenu with refs
ammarahm-ed819fc614df68
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 18aadde3a..37fe5cf6d 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -1,13 +1,7 @@import React, {useEffect, useState} from 'react';-import {Platform, StatusBar, View, Text} from 'react-native';+import {Platform, StatusBar, View} from 'react-native';import * as Animatable from 'react-native-animatable';-import {- getColorScheme,- WEIGHT,- SIZE,- scale,- updateSize,-} from './src/common/common';+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';@@ -19,12 +13,8 @@ import Orientation from 'react-native-orientation';import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';import {eCloseFullscreenEditor,- eCloseSideMenu,- eDisableGestures,eDispatchAction,- eEnableGestures,eOpenFullscreenEditor,- eOpenSideMenu,} from './src/services/events';import NavigationService, {AppContainer,@@ -35,32 +25,18 @@ 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';-let sideMenuRef;let editorRef;let outColors;const App = () => {const [state, dispatch] = useTracked();- const {colors, loading} = state;+ const {colors} = 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);@@ -115,11 +91,6 @@ const App = () => {useEffect(() => {DDS.isTab ? Orientation.lockToLandscape() : Orientation.lockToPortrait();- eSubscribeEvent(eOpenSideMenu, openSidebar);- eSubscribeEvent(eCloseSideMenu, closeSidebar);-- eSubscribeEvent(eDisableGestures, disableGestures);- eSubscribeEvent(eEnableGestures, enableGestures);eSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);eSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);@@ -127,12 +98,6 @@ const App = () => {return () => {eUnSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);eUnSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);-- eUnSubscribeEvent(eOpenSideMenu, openSidebar);- eUnSubscribeEvent(eCloseSideMenu, closeSidebar);-- eUnSubscribeEvent(eDisableGestures, disableGestures);- eUnSubscribeEvent(eEnableGestures, enableGestures);};}, []);@@ -189,99 +154,10 @@ const App = () => {flexDirection: 'row',backgroundColor: colors.bg,}}>- <Animatable.View- transition={['translateX']}- useNativeDriver={true}- duration={1000}- delay={2500}- style={{- width: '50%',- left: 0,- height: '100%',- position: 'absolute',- backgroundColor: colors.accent,- justifyContent: 'center',- alignItems: 'flex-end',- zIndex: 999,- transform: [- {- translateX: loading ? 0 : -w * 2,- },- ],- }}>- <Animatable.Text- animation="fadeIn"- duration={300}- delay={150}- style={{- color: 'white',- fontFamily: WEIGHT.bold,- fontSize: SIZE.xxl,- }}>- notes- </Animatable.Text>- <Animatable.Text- animation="fadeIn"- duration={300}- delay={600}- style={{- color: 'white',- fontFamily: WEIGHT.regular,- fontSize: SIZE.md,- marginTop: 15,- }}>- A safe plac- </Animatable.Text>- </Animatable.View>- <Animatable.View- transition={['translateX']}- useNativeDriver={true}- duration={1000}- delay={2500}- style={{- width: '50%',- right: 0,- height: '100%',- position: 'absolute',- backgroundColor: colors.accent,- justifyContent: 'center',- alignItems: 'flex-start',- zIndex: 999,- transform: [- {- translateX: loading ? 0 : w * 2,- },- ],- }}>- <Animatable.Text- animation="fadeIn"- duration={300}- delay={150}- style={{- color: 'white',- fontFamily: WEIGHT.bold,- fontSize: SIZE.xxl,- }}>- nook- </Animatable.Text>- <Animatable.Text- animation="fadeIn"- duration={300}- delay={600}- style={{- color: 'white',- fontFamily: WEIGHT.regular,- fontSize: SIZE.md,- marginTop: 15,- }}>- e to write- </Animatable.Text>- </Animatable.View>-+ <Loading />{DDS.isTab ? (<><ModalMenu colors={colors} />-<Animatable.Viewanimation="fadeIn"useNativeDriver={true}@@ -332,7 +208,7 @@ const App = () => {</>) : (<SideMenu- ref={ref => (sideMenuRef = ref)}+ ref={sideMenuRef}bounceBackOnOverdraw={false}contentContainerStyle={{opacity: 0,@@ -342,7 +218,9 @@ const App = () => {<Menuhide={false}colors={colors}- close={() => sideMenuRef.openMenu(!sideMenuRef.isOpen)}+ close={() =>+ sideMenuRef.current?.openMenu(!sideMenuRef.current?.isOpen)+ }/>}openMenuOffset={w / 1.5}>diff --git a/apps/mobile/loading.js b/apps/mobile/loading.jsindex 8fb0e6d62..f153f7bee 100755--- a/apps/mobile/loading.js+++ b/apps/mobile/loading.js@@ -1,25 +1,103 @@+import React from 'react';+import {SIZE, WEIGHT} from './src/common/common';+import * as Animatable from 'react-native-animatable';+import {useTracked} from './src/provider';+import {w} from './src/utils/utils';+export const Loading = () => {+ const [state, dispatch] = useTracked();+ const {colors, loading} = state;-import React, {Component} from 'react';-import {- View,- Text- } from 'react-native';---export default class Loading extends Component {-render() {- return <View- style={{- width:"100%",- height:"100%",- justifyContent:"center",- alignItems:'center'- }}- >- <Text>- Loading Screen- </Text>- </View>-}-};\ No newline at end of file+ return (+ <>+ <Animatable.View+ transition={['translateX']}+ useNativeDriver={true}+ duration={1000}+ delay={2500}+ style={{+ width: '50%',+ left: 0,+ height: '100%',+ position: 'absolute',+ backgroundColor: colors.accent,+ justifyContent: 'center',+ alignItems: 'flex-end',+ zIndex: 999,+ transform: [+ {+ translateX: loading ? 0 : -w * 2,+ },+ ],+ }}>+ <Animatable.Text+ animation="fadeIn"+ duration={300}+ delay={150}+ style={{+ color: 'white',+ fontFamily: WEIGHT.bold,+ fontSize: SIZE.xxl,+ }}>+ notes+ </Animatable.Text>+ <Animatable.Text+ animation="fadeIn"+ duration={300}+ delay={600}+ style={{+ color: 'white',+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.md,+ marginTop: 15,+ }}>+ A safe plac+ </Animatable.Text>+ </Animatable.View>+ <Animatable.View+ transition={['translateX']}+ useNativeDriver={true}+ duration={1000}+ delay={2500}+ style={{+ width: '50%',+ right: 0,+ height: '100%',+ position: 'absolute',+ backgroundColor: colors.accent,+ justifyContent: 'center',+ alignItems: 'flex-start',+ zIndex: 999,+ transform: [+ {+ translateX: loading ? 0 : w * 2,+ },+ ],+ }}>+ <Animatable.Text+ animation="fadeIn"+ duration={300}+ delay={150}+ style={{+ color: 'white',+ fontFamily: WEIGHT.bold,+ fontSize: SIZE.xxl,+ }}>+ nook+ </Animatable.Text>+ <Animatable.Text+ animation="fadeIn"+ duration={300}+ delay={600}+ style={{+ color: 'white',+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.md,+ marginTop: 15,+ }}>+ e to write+ </Animatable.Text>+ </Animatable.View>+ </>+ );+};diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.jsindex 7a29a0140..d19a09e70 100644--- a/apps/mobile/src/components/header/index.js+++ b/apps/mobile/src/components/header/index.js@@ -7,11 +7,12 @@ import {useTracked} from '../../provider';import {eSendEvent} from '../../services/eventManager';import {eCloseLoginDialog} from '../../services/events';import NavigationService from '../../services/NavigationService';-import {SideMenuEvent, DDS} from '../../utils/utils';+import {DDS} from '../../utils/utils';import {moveNoteHideEvent} from '../DialogManager';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu';import {ACTIONS} from '../../provider/actions';+import {sideMenuRef} from '../../utils/refs';export const Header = ({heading,canGoBack = true,@@ -93,7 +94,7 @@ export const Header = ({<TouchableOpacityhitSlop={{top: 20, bottom: 20, left: 50, right: 40}}onPress={() => {- SideMenuEvent.open();+ sideMenuRef.current?.openMenu(true);}}style={{justifyContent: 'center',diff --git a/apps/mobile/src/provider/reducer.js b/apps/mobile/src/provider/reducer.jsindex 1f5229918..b254eb14a 100644--- a/apps/mobile/src/provider/reducer.js+++ b/apps/mobile/src/provider/reducer.js@@ -1,5 +1,6 @@-import {SideMenuEvent, history, db} from '../utils/utils';+import {history, db} from '../utils/utils';import {ACTIONS} from './actions';+import {sideMenuRef} from '../utils/refs';export const reducer = (state, action) => {switch (action.type) {@@ -85,9 +86,9 @@ export const reducer = (state, action) => {}case ACTIONS.SELECTION_MODE: {if (action.enabled) {- SideMenuEvent.disable();+ sideMenuRef.current?.setGestureEnabled(false);} else {- SideMenuEvent.enable();+ sideMenuRef.current?.setGestureEnabled(true);}return {@@ -104,7 +105,7 @@ export const reducer = (state, action) => {}history.selectedItemsList = selectedItems;if (selectedItems.length === 0) {- SideMenuEvent.enable();+ sideMenuRef.current?.setGestureEnabled(true);}return {...state,@@ -114,7 +115,7 @@ export const reducer = (state, action) => {}case ACTIONS.CLEAR_SELECTION: {history.selectedItemsList = [];- SideMenuEvent.enable();+ sideMenuRef.current?.setGestureEnabled(true);return {...state,selectedItemsList: [],diff --git a/apps/mobile/src/utils/refs.js b/apps/mobile/src/utils/refs.jsnew file mode 100644index 000000000..b935b03ef--- /dev/null+++ b/apps/mobile/src/utils/refs.js@@ -0,0 +1,3 @@+import {createRef} from 'react';++export const sideMenuRef = createRef();diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.jsindex e1f01789d..0bff4e2a2 100755--- a/apps/mobile/src/utils/utils.js+++ b/apps/mobile/src/utils/utils.js@@ -168,21 +168,6 @@ export const timeConverter = timestamp => {return time;};-export const SideMenuEvent = {- open: () => {- eSendEvent(eOpenSideMenu);- },- close: () => {- eSendEvent(eCloseSideMenu);- },- disable: () => {- eSendEvent(eDisableGestures);- },- enable: () => {- eSendEvent(eEnableGestures);- },-};-const isValidHex = hex => /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);const getChunksFromString = (st, chunkSize) =>diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.jsindex 30dbd4946..df616cda6 100755--- a/apps/mobile/src/views/Editor/index.js+++ b/apps/mobile/src/views/Editor/index.js@@ -28,14 +28,7 @@ import {refreshNotesPage,} from '../../services/events';import {exitEditorAnimation} from '../../utils/animations';-import {- editing,- SideMenuEvent,- timeConverter,- ToastEvent,- DDS,- db,-} from '../../utils/utils';+import {editing, timeConverter, ToastEvent, DDS, db} from '../../utils/utils';import {ActionSheetEvent,simpleDialogEvent,@@ -80,7 +73,7 @@ const Editor = ({noMenu}) => {const loadNote = async item => {EditorWebView.current?.requestFocus();- noMenu ? null : SideMenuEvent.disable();+ noMenu ? null : sideMenuRef.current?.setGestureEnabled(false);if (note && note.id) {dispatch({type: ACTIONS.NOTES});if (item && item.type === 'new') {@@ -390,8 +383,8 @@ const Editor = ({noMenu}) => {await clearEditor();if (noMenu) return true;- DDS.isTab ? SideMenuEvent.open() : null;- SideMenuEvent.enable();+ DDS.isTab ? sideMenuRef.current?.openMenu(true) : null;+ sideMenuRef.current?.setGestureEnabled(true);EditorWebView.current?.reload();// Keyboard.dismiss();@@ -472,8 +465,8 @@ const Editor = ({noMenu}) => {}await clearEditor();EditorWebView.current?.reload();- DDS.isTab ? SideMenuEvent.open() : null;- SideMenuEvent.enable();+ DDS.isTab ? sideMenuRef.current?.openMenu(true) : null;+ sideMenuRef.current?.setGestureEnabled(true);}}}style={{diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex e7c710a15..6b3b4965a 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -8,9 +8,10 @@ import SelectionHeader from '../../components/SelectionHeader';import {useTracked} from '../../provider';import {ACTIONS} from '../../provider/actions';import {eSendEvent} from '../../services/eventManager';-import {SideMenuEvent, DDS} from '../../utils/utils';+import {DDS} from '../../utils/utils';import {eScrollEvent, eOnLoadNote} from '../../services/events';import {openEditorAnimation} from '../../utils/animations';+import {sideMenuRef} from '../../utils/refs';let count = 0;export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(SafeAreaView,@@ -48,8 +49,8 @@ export const Home = ({navigation}) => {if (DDS.isTab) {eSendEvent(eOnLoadNote, {type: 'new'});} else {- SideMenuEvent.close();- SideMenuEvent.disable();+ sideMenuRef.current?.openMenu(false);+ sideMenuRef.current?.setGestureEnabled(false);eSendEvent(eOnLoadNote, {type: 'new'});openEditorAnimation();}diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.jsindex 12b916793..92020f9ad 100644--- a/apps/mobile/src/views/Notes/index.js+++ b/apps/mobile/src/views/Notes/index.js@@ -18,7 +18,8 @@ import {refreshNotesPage,} from '../../services/events';import {openEditorAnimation} from '../../utils/animations';-import {db, DDS, editing, SideMenuEvent, ToastEvent} from '../../utils/utils';+import {db, DDS, editing, ToastEvent} from '../../utils/utils';+import {sideMenuRef} from '../../utils/refs';export const Notes = ({navigation}) => {const [state, dispatch] = useTracked();@@ -155,8 +156,8 @@ export const Notes = ({navigation}) => {if (DDS.isTab) {eSendEvent(eOnLoadNote, {type: 'new'});} else {- SideMenuEvent.close();- SideMenuEvent.disable();+ sideMenuRef.current?.openMenu(false);+ sideMenuRef.current?.setGestureEnabled(false);eSendEvent(eOnLoadNote, {type: 'new'});openEditorAnimation();}