2020-02-06 13:08:35 +05:00
|
|
|
import Storage from 'notes-core/api/index';
|
2020-01-24 23:34:33 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
2020-01-27 00:25:19 +05:00
|
|
|
import {Platform, StatusBar, View, Text} from 'react-native';
|
2020-01-24 23:34:33 +05:00
|
|
|
import * as Animatable from 'react-native-animatable';
|
2020-02-23 11:47:14 +05:00
|
|
|
import {
|
|
|
|
|
getColorScheme,
|
|
|
|
|
WEIGHT,
|
|
|
|
|
SIZE,
|
|
|
|
|
scale,
|
|
|
|
|
updateSize,
|
|
|
|
|
} from './src/common/common';
|
2020-01-25 23:24:01 +05:00
|
|
|
import {DialogManager} from './src/components/DialogManager';
|
2020-01-24 23:34:33 +05:00
|
|
|
import {Menu} from './src/components/Menu';
|
2020-01-22 02:49:52 +05:00
|
|
|
import {ModalMenu} from './src/components/ModalMenu';
|
2020-01-24 23:34:33 +05:00
|
|
|
import SideMenu from './src/components/SideMenu';
|
|
|
|
|
import {Toast} from './src/components/Toast';
|
|
|
|
|
import {useTracked} from './src/provider';
|
|
|
|
|
import {ACTIONS} from './src/provider/actions';
|
2020-02-22 20:00:57 +05:00
|
|
|
import Orientation from 'react-native-orientation';
|
2020-01-25 19:42:11 +05:00
|
|
|
import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';
|
2020-01-25 20:12:47 +05:00
|
|
|
import {
|
2020-01-25 23:24:01 +05:00
|
|
|
eCloseFullscreenEditor,
|
2020-01-25 20:12:47 +05:00
|
|
|
eCloseSideMenu,
|
|
|
|
|
eDisableGestures,
|
2020-01-25 23:24:01 +05:00
|
|
|
eDispatchAction,
|
2020-01-25 20:12:47 +05:00
|
|
|
eEnableGestures,
|
|
|
|
|
eOpenFullscreenEditor,
|
2020-01-25 23:24:01 +05:00
|
|
|
eOpenSideMenu,
|
2020-01-25 20:12:47 +05:00
|
|
|
} from './src/services/events';
|
2020-01-25 23:24:01 +05:00
|
|
|
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';
|
2020-03-14 13:37:07 +05:00
|
|
|
import Animated from 'react-native-reanimated';
|
2020-03-10 13:36:33 +05:00
|
|
|
import MMKV from 'react-native-mmkv-storage';
|
2020-02-23 11:10:55 +05:00
|
|
|
import {defaultState} from './src/provider/defaultState';
|
2020-03-03 09:49:54 +05:00
|
|
|
import {EditorPosition} from './src/utils/animations';
|
2019-12-14 16:00:16 +05:00
|
|
|
export const DDS = new DeviceDetectionService();
|
2019-12-11 01:10:04 +05:00
|
|
|
export const db = new Storage(StorageInterface);
|
2020-01-14 20:48:03 +05:00
|
|
|
|
2020-01-14 12:29:02 +05:00
|
|
|
let sideMenuRef;
|
2020-01-22 02:49:52 +05:00
|
|
|
let editorRef;
|
2020-01-27 00:57:37 +05:00
|
|
|
let outColors;
|
2020-02-06 23:38:40 +05:00
|
|
|
|
2019-11-15 01:17:59 +05:00
|
|
|
const App = () => {
|
2020-01-17 00:23:16 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
2020-01-27 00:25:19 +05:00
|
|
|
const {colors, loading} = state;
|
2020-01-17 00:23:16 +05:00
|
|
|
const [init, setInit] = useState(false);
|
2020-01-22 02:49:52 +05:00
|
|
|
const [fullscreen, setFullscreen] = useState(false);
|
2019-12-11 01:10:04 +05:00
|
|
|
|
2020-01-17 21:04:21 +05:00
|
|
|
const openSidebar = () => {
|
2020-01-24 22:52:34 +05:00
|
|
|
DDS.isTab ? null : sideMenuRef.openMenu(true);
|
2020-01-17 21:04:21 +05:00
|
|
|
};
|
|
|
|
|
const closeSidebar = () => {
|
2020-01-24 22:52:34 +05:00
|
|
|
DDS.isTab ? null : sideMenuRef.openMenu(false);
|
2020-01-17 21:04:21 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const disableGestures = () => {
|
2020-01-22 02:49:52 +05:00
|
|
|
DDS.isTab ? null : sideMenuRef.setGestureEnabled(false);
|
2020-01-17 21:04:21 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const enableGestures = () => {
|
2020-01-22 02:49:52 +05:00
|
|
|
DDS.isTab ? null : sideMenuRef.setGestureEnabled(true);
|
2020-01-17 21:04:21 +05:00
|
|
|
};
|
|
|
|
|
|
2020-01-22 02:49:52 +05:00
|
|
|
const showFullScreenEditor = () => {
|
|
|
|
|
setFullscreen(true);
|
2020-01-27 00:57:37 +05:00
|
|
|
|
2020-01-22 02:49:52 +05:00
|
|
|
editorRef.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
width: '100%',
|
|
|
|
|
zIndex: 999,
|
|
|
|
|
paddingHorizontal: 100,
|
2020-01-27 00:57:37 +05:00
|
|
|
backgroundColor: outColors.bg,
|
2020-01-22 02:49:52 +05:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-27 00:57:37 +05:00
|
|
|
useEffect(() => {
|
|
|
|
|
outColors = colors;
|
|
|
|
|
}, [colors]);
|
|
|
|
|
|
2020-01-22 02:49:52 +05:00
|
|
|
const closeFullScreenEditor = () => {
|
|
|
|
|
setFullscreen(false);
|
|
|
|
|
editorRef.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
position: 'relative',
|
|
|
|
|
width: '68%',
|
|
|
|
|
zIndex: null,
|
|
|
|
|
paddingHorizontal: 0,
|
2020-01-25 20:12:47 +05:00
|
|
|
backgroundColor: 'transparent',
|
2020-01-22 02:49:52 +05:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-22 20:00:57 +05:00
|
|
|
const _onOrientationChange = o => {
|
|
|
|
|
// Currently orientation is locked on tablet.
|
|
|
|
|
/* DDS.checkOrientation();
|
|
|
|
|
setTimeout(() => {
|
2020-03-10 23:19:16 +05:00
|
|
|
|
2020-02-22 20:00:57 +05:00
|
|
|
forceUpdate();
|
|
|
|
|
}, 1000); */
|
|
|
|
|
};
|
2020-01-17 21:04:21 +05:00
|
|
|
useEffect(() => {
|
2020-02-22 20:00:57 +05:00
|
|
|
Orientation.addOrientationListener(_onOrientationChange);
|
2020-01-25 19:42:11 +05:00
|
|
|
eSubscribeEvent(eDispatchAction, type => {
|
2020-01-17 21:04:21 +05:00
|
|
|
dispatch(type);
|
|
|
|
|
});
|
|
|
|
|
return () => {
|
2020-01-25 19:42:11 +05:00
|
|
|
eUnSubscribeEvent(eDispatchAction, type => {
|
2020-01-17 21:04:21 +05:00
|
|
|
dispatch(type);
|
2019-12-04 19:38:19 +05:00
|
|
|
});
|
2020-02-22 20:00:57 +05:00
|
|
|
Orientation.removeOrientationListener(_onOrientationChange);
|
2019-11-23 06:25:22 +05:00
|
|
|
};
|
2019-11-29 11:31:43 +05:00
|
|
|
}, []);
|
|
|
|
|
|
2020-01-25 23:47:17 +05:00
|
|
|
useEffect(() => {
|
2020-02-23 09:40:06 +05:00
|
|
|
DDS.isTab ? Orientation.lockToLandscape() : Orientation.lockToPortrait();
|
2020-01-25 23:47:17 +05:00
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2019-12-07 12:05:15 +05:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
|
StatusBar.setBackgroundColor('transparent');
|
|
|
|
|
StatusBar.setTranslucent(true);
|
|
|
|
|
StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
2019-12-21 10:38:40 +05:00
|
|
|
useEffect(() => {
|
2020-01-17 21:04:21 +05:00
|
|
|
updateAppTheme().then(() => {
|
2020-02-12 02:09:41 +05:00
|
|
|
db.init().then(async () => {
|
|
|
|
|
let user = await db.user.get();
|
|
|
|
|
dispatch({type: ACTIONS.USER, user: user});
|
|
|
|
|
|
2020-01-17 21:04:21 +05:00
|
|
|
setInit(true);
|
|
|
|
|
});
|
2019-12-21 10:38:40 +05:00
|
|
|
});
|
2020-01-17 21:26:01 +05:00
|
|
|
}, []);
|
2019-12-21 10:38:40 +05:00
|
|
|
|
2020-01-24 22:52:34 +05:00
|
|
|
async function updateAppTheme(colors = colors) {
|
2020-01-17 21:04:21 +05:00
|
|
|
let newColors = await getColorScheme(colors);
|
2020-03-10 13:36:33 +05:00
|
|
|
let s = await MMKV.getString('settings');
|
2020-02-23 11:47:14 +05:00
|
|
|
if (typeof s !== 'string') {
|
|
|
|
|
s = defaultState.settings;
|
|
|
|
|
|
|
|
|
|
s = JSON.stringify(s);
|
2020-03-10 13:36:33 +05:00
|
|
|
await MMKV.setString('settings', s);
|
2020-02-23 11:47:14 +05:00
|
|
|
dispatch({type: ACTIONS.SETTINGS, s});
|
|
|
|
|
} else {
|
|
|
|
|
s = JSON.parse(s);
|
|
|
|
|
scale.fontScale = s.fontScale;
|
2020-03-03 09:49:54 +05:00
|
|
|
|
2020-02-23 11:47:14 +05:00
|
|
|
updateSize();
|
2020-03-03 09:49:54 +05:00
|
|
|
|
2020-02-23 11:47:14 +05:00
|
|
|
dispatch({type: ACTIONS.SETTINGS, settings: {...s}});
|
|
|
|
|
}
|
2020-01-17 21:04:21 +05:00
|
|
|
dispatch({type: ACTIONS.THEME, colors: newColors});
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 00:23:16 +05:00
|
|
|
if (!init) {
|
2020-01-14 20:48:03 +05:00
|
|
|
return <></>;
|
2019-12-11 01:10:04 +05:00
|
|
|
}
|
2019-11-17 16:02:19 +05:00
|
|
|
return (
|
2020-01-17 21:04:21 +05:00
|
|
|
<>
|
2020-01-27 00:25:19 +05:00
|
|
|
<Animatable.View
|
|
|
|
|
transition="backgroundColor"
|
|
|
|
|
duration={300}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
}}>
|
2020-01-25 00:02:13 +05:00
|
|
|
<Animatable.View
|
2020-01-27 00:25:19 +05:00
|
|
|
transition={['translateX']}
|
|
|
|
|
useNativeDriver={true}
|
|
|
|
|
duration={1000}
|
|
|
|
|
delay={2500}
|
2020-01-25 00:02:13 +05:00
|
|
|
style={{
|
2020-01-27 00:25:19 +05:00
|
|
|
width: '50%',
|
|
|
|
|
left: 0,
|
2020-01-25 00:02:13 +05:00
|
|
|
height: '100%',
|
2020-01-27 00:25:19 +05:00
|
|
|
position: 'absolute',
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
|
zIndex: 999,
|
|
|
|
|
transform: [
|
|
|
|
|
{
|
|
|
|
|
translateX: loading ? 0 : -w * 2,
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-01-25 00:02:13 +05:00
|
|
|
}}>
|
2020-01-27 00:25:19 +05:00
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
{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,
|
|
|
|
|
}}>
|
2020-01-22 02:49:52 +05:00
|
|
|
<AppContainer
|
|
|
|
|
style={{
|
2020-01-27 00:25:19 +05:00
|
|
|
width: '100%',
|
2020-01-22 02:49:52 +05:00
|
|
|
height: '100%',
|
|
|
|
|
}}
|
|
|
|
|
ref={navigatorRef => {
|
|
|
|
|
NavigationService.setTopLevelNavigator(navigatorRef);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2020-01-27 00:25:19 +05:00
|
|
|
</Animatable.View>
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
ref={ref => (editorRef = ref)}
|
|
|
|
|
style={{
|
|
|
|
|
width: '68%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
|
}}>
|
|
|
|
|
<Editor noMenu={fullscreen ? false : true} />
|
|
|
|
|
</View>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<SideMenu
|
|
|
|
|
ref={ref => (sideMenuRef = ref)}
|
|
|
|
|
bounceBackOnOverdraw={false}
|
|
|
|
|
contentContainerStyle={{
|
|
|
|
|
opacity: 0,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
}}
|
|
|
|
|
menu={
|
|
|
|
|
<Menu
|
|
|
|
|
hide={false}
|
|
|
|
|
colors={colors}
|
|
|
|
|
close={() => sideMenuRef.openMenu(!sideMenuRef.isOpen)}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2020-02-10 10:43:26 +05:00
|
|
|
openMenuOffset={w / 1.5}>
|
2020-01-27 00:25:19 +05:00
|
|
|
<AppContainer
|
|
|
|
|
style={{
|
|
|
|
|
width: DDS.isTab ? '70%' : '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
}}
|
|
|
|
|
ref={navigatorRef => {
|
|
|
|
|
NavigationService.setTopLevelNavigator(navigatorRef);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</SideMenu>
|
|
|
|
|
)}
|
2020-03-03 09:49:54 +05:00
|
|
|
|
|
|
|
|
<Animated.View
|
|
|
|
|
ref={ref => (editorRef = ref)}
|
2020-03-03 10:31:50 +05:00
|
|
|
onResponderTerminationRequest={true}
|
|
|
|
|
onStartShouldSetResponderCapture={false}
|
|
|
|
|
onStartShouldSetResponder={false}
|
|
|
|
|
onMoveShouldSetResponder={false}
|
|
|
|
|
onMoveShouldSetResponderCapture={false}
|
2020-03-03 09:49:54 +05:00
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2020-03-03 10:31:50 +05:00
|
|
|
alignSelf: 'flex-end',
|
2020-03-03 09:49:54 +05:00
|
|
|
position: 'absolute',
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
elevation: 10,
|
2020-03-03 10:31:50 +05:00
|
|
|
|
2020-03-03 09:49:54 +05:00
|
|
|
transform: [
|
|
|
|
|
{
|
|
|
|
|
translateX: EditorPosition,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}}>
|
|
|
|
|
<Editor noMenu={false} />
|
|
|
|
|
</Animated.View>
|
|
|
|
|
|
2020-01-27 00:25:19 +05:00
|
|
|
<Toast />
|
2020-03-03 09:49:54 +05:00
|
|
|
|
2020-01-27 00:25:19 +05:00
|
|
|
<DialogManager colors={colors} />
|
2020-01-22 02:49:52 +05:00
|
|
|
</Animatable.View>
|
2020-01-17 21:04:21 +05:00
|
|
|
</>
|
2019-11-15 01:17:59 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|