Files
notesnook/apps/mobile/index.mobile.js

116 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-05-06 15:06:00 +05:00
import React, {createRef, useEffect, useState} from 'react';
2020-05-06 01:55:05 +05:00
import {Platform, StatusBar, View} from 'react-native';
2020-03-15 11:03:35 +05:00
import * as Animatable from 'react-native-animatable';
2020-05-06 15:06:00 +05:00
import DrawerLayout from 'react-native-drawer-layout';
2020-05-06 01:55:05 +05:00
import Animated from 'react-native-reanimated';
import {Menu} from './src/components/Menu';
import {useTracked} from './src/provider';
2020-05-06 15:06:00 +05:00
import {NavigationStack} from './src/services/Navigator';
2020-05-12 02:56:22 +05:00
import {EditorOpacity, EditorPosition, EditorScale} from './src/utils/animations';
2020-05-06 01:55:05 +05:00
import {sideMenuRef} from './src/utils/refs';
2020-05-06 15:06:00 +05:00
import {DDS} from './src/utils/utils';
2020-03-15 10:20:34 +05:00
import Editor from './src/views/Editor';
2020-05-06 15:18:47 +05:00
import { eSubscribeEvent, eUnSubscribeEvent } from './src/services/eventManager';
import { eOpenSideMenu, eCloseSideMenu } from './src/services/events';
2020-03-15 10:20:34 +05:00
2020-03-15 11:03:35 +05:00
const editorRef = createRef();
2020-03-15 10:20:34 +05:00
export const Initialize = () => {
const [state, dispatch] = useTracked();
2020-05-06 01:55:05 +05:00
const {colors} = state;
2020-05-06 15:18:47 +05:00
const [locked,setLocked] = useState(false);
2020-03-15 10:20:34 +05:00
useEffect(() => {
if (Platform.OS === 'android') {
StatusBar.setBackgroundColor('transparent');
StatusBar.setTranslucent(true);
StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
}
}, []);
2020-05-06 15:06:00 +05:00
2020-05-06 15:18:47 +05:00
const setGestureDisabled = () =>{
setLocked(true);
}
const setGestureEnabled = () => {
setLocked(false);
}
useEffect(() => {
eSubscribeEvent(eOpenSideMenu,setGestureEnabled);
eSubscribeEvent(eCloseSideMenu,setGestureDisabled);
return () => {
eUnSubscribeEvent(eOpenSideMenu,setGestureEnabled);
eUnSubscribeEvent(eCloseSideMenu,setGestureDisabled);
}
},[])
2020-03-15 10:20:34 +05:00
return (
2020-03-15 11:03:35 +05:00
<Animatable.View
transition="backgroundColor"
duration={300}
style={{
width: '100%',
height: '100%',
flexDirection: 'row',
backgroundColor: colors.bg,
}}>
2020-05-06 15:06:00 +05:00
<DrawerLayout
2020-03-15 10:20:34 +05:00
ref={sideMenuRef}
2020-05-06 15:06:00 +05:00
style={{
2020-03-15 10:20:34 +05:00
opacity: 0,
backgroundColor: colors.bg,
}}
2020-05-06 15:06:00 +05:00
keyboardDismissMode="ondrag"
drawerWidth={300}
2020-05-06 15:18:47 +05:00
drawerLockMode={locked? "locked-closed" : 'unlocked'}
2020-05-06 15:06:00 +05:00
useNativeAnimations={true}
renderNavigationView={() => (
2020-03-15 10:20:34 +05:00
<Menu
hide={false}
colors={colors}
2020-05-06 15:06:00 +05:00
close={() => sideMenuRef.current?.closeDrawer()}
2020-03-15 10:20:34 +05:00
/>
2020-05-06 15:06:00 +05:00
)}>
2020-05-06 01:55:05 +05:00
<View
2020-03-15 10:20:34 +05:00
style={{
width: DDS.isTab ? '70%' : '100%',
height: '100%',
backgroundColor: colors.bg,
2020-05-06 01:55:05 +05:00
}}>
<NavigationStack />
</View>
2020-05-06 15:06:00 +05:00
</DrawerLayout>
2020-03-15 10:49:11 +05:00
2020-03-15 10:20:34 +05:00
<Animated.View
2020-03-15 11:03:35 +05:00
ref={editorRef}
2020-03-15 10:20:34 +05:00
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,
2020-05-06 01:55:05 +05:00
opacity: EditorOpacity,
2020-03-15 10:20:34 +05:00
transform: [
{
translateX: EditorPosition,
},
2020-05-12 02:56:22 +05:00
{
scaleX:EditorScale,
},
{
scaleY:EditorScale
}
2020-03-15 10:20:34 +05:00
],
}}>
<Editor noMenu={false} />
</Animated.View>
2020-03-15 11:03:35 +05:00
</Animatable.View>
2020-03-15 10:20:34 +05:00
);
};