2021-02-15 11:06:40 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
2021-02-12 16:26:11 +05:00
|
|
|
import {View} from 'react-native';
|
2021-01-11 14:29:50 +05:00
|
|
|
import Orientation from 'react-native-orientation';
|
2021-02-15 11:06:40 +05:00
|
|
|
import Animated, {Easing} from 'react-native-reanimated';
|
|
|
|
|
import AnimatedProgress from 'react-native-reanimated-progress-bar';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {SafeAreaProvider} from 'react-native-safe-area-context';
|
2020-12-10 09:54:48 +05:00
|
|
|
import SplashScreen from 'react-native-splash-screen';
|
2021-01-11 14:29:50 +05:00
|
|
|
import {AppRootEvents} from './AppRootEvents';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {RootView} from './initializer.root';
|
|
|
|
|
import {useTracked} from './src/provider';
|
|
|
|
|
import {Actions} from './src/provider/Actions';
|
|
|
|
|
import {DDS} from './src/services/DeviceDetection';
|
2021-01-17 12:53:04 +05:00
|
|
|
import {
|
|
|
|
|
eSendEvent,
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
|
|
|
|
} from './src/services/EventManager';
|
2021-02-16 16:11:10 +05:00
|
|
|
import Navigation from './src/services/Navigation';
|
2020-12-20 23:03:02 +05:00
|
|
|
import SettingsService from './src/services/SettingsService';
|
2021-02-12 16:26:11 +05:00
|
|
|
import {changeAppScale} from './src/utils/Animations';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {db} from './src/utils/DB';
|
2021-02-10 15:58:08 +05:00
|
|
|
import {eDispatchAction, eOpenSideMenu} from './src/utils/Events';
|
2021-02-12 16:26:11 +05:00
|
|
|
import {sleep} from './src/utils/TimeUtils';
|
2021-01-08 12:30:05 +05:00
|
|
|
import EditorRoot from './src/views/Editor/EditorRoot';
|
2020-11-16 12:36:41 +05:00
|
|
|
|
2021-02-12 16:26:11 +05:00
|
|
|
let initStatus = false;
|
2019-11-15 01:17:59 +05:00
|
|
|
const App = () => {
|
2020-12-22 12:38:31 +05:00
|
|
|
const [, dispatch] = useTracked();
|
2020-11-16 12:36:41 +05:00
|
|
|
|
2021-01-11 14:29:50 +05:00
|
|
|
useEffect(() => {
|
2021-02-10 15:58:08 +05:00
|
|
|
(async () => {
|
|
|
|
|
try {
|
2021-02-12 16:26:11 +05:00
|
|
|
scaleV.setValue(0.95);
|
|
|
|
|
opacityV.setValue(1);
|
2021-02-10 15:58:08 +05:00
|
|
|
Orientation.getOrientation((e, r) => {
|
|
|
|
|
DDS.checkSmallTab(r);
|
|
|
|
|
dispatch({
|
|
|
|
|
type: Actions.DEVICE_MODE,
|
|
|
|
|
state: DDS.isLargeTablet()
|
|
|
|
|
? 'tablet'
|
|
|
|
|
: DDS.isSmallTab
|
|
|
|
|
? 'smallTablet'
|
|
|
|
|
: 'mobile',
|
|
|
|
|
});
|
2021-02-12 16:26:11 +05:00
|
|
|
SplashScreen.hide();
|
2021-02-06 13:28:27 +05:00
|
|
|
});
|
2021-02-12 16:26:11 +05:00
|
|
|
await SettingsService.init();
|
2021-02-10 15:58:08 +05:00
|
|
|
await db.init();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
} finally {
|
2021-02-12 16:26:11 +05:00
|
|
|
initStatus = true;
|
2021-02-15 11:06:40 +05:00
|
|
|
loadMainApp();
|
2021-02-10 15:58:08 +05:00
|
|
|
}
|
|
|
|
|
})();
|
2021-01-11 14:29:50 +05:00
|
|
|
}, []);
|
2020-12-20 23:01:35 +05:00
|
|
|
|
2021-02-09 16:34:18 +05:00
|
|
|
const _dispatch = (data) => {
|
|
|
|
|
dispatch(data);
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
useEffect(() => {
|
2021-02-09 16:34:18 +05:00
|
|
|
eSubscribeEvent(eDispatchAction, _dispatch);
|
2020-12-20 23:01:35 +05:00
|
|
|
return () => {
|
2021-02-09 16:34:18 +05:00
|
|
|
eUnSubscribeEvent(eDispatchAction, _dispatch);
|
2020-12-20 23:01:35 +05:00
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2021-02-12 16:26:11 +05:00
|
|
|
const loadMainApp = (origin) => {
|
|
|
|
|
if (initStatus) {
|
2021-02-15 11:06:40 +05:00
|
|
|
eSendEvent('load_overlay', origin);
|
2021-02-12 16:26:11 +05:00
|
|
|
dispatch({type: Actions.ALL});
|
|
|
|
|
}
|
2020-12-10 13:06:59 +05:00
|
|
|
};
|
2020-12-09 22:16:22 +05:00
|
|
|
|
2020-10-24 13:47:31 +05:00
|
|
|
return (
|
2020-11-23 11:30:55 +05:00
|
|
|
<SafeAreaProvider>
|
2020-12-22 12:38:31 +05:00
|
|
|
<RootView />
|
2021-01-08 12:30:05 +05:00
|
|
|
<EditorRoot />
|
2021-01-11 14:29:50 +05:00
|
|
|
<AppRootEvents />
|
2021-02-12 16:26:11 +05:00
|
|
|
<Overlay onLoad={loadMainApp} />
|
2020-11-23 11:30:55 +05:00
|
|
|
</SafeAreaProvider>
|
2020-10-24 13:47:31 +05:00
|
|
|
);
|
2019-11-15 01:17:59 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|
2021-02-12 16:26:11 +05:00
|
|
|
|
|
|
|
|
const scaleV = new Animated.Value(0.95);
|
|
|
|
|
const opacityV = new Animated.Value(1);
|
|
|
|
|
|
|
|
|
|
const Overlay = ({onLoad}) => {
|
|
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const colors = state.colors;
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const [progress, setProgress] = useState(4);
|
|
|
|
|
const [opacity, setOpacity] = useState(true);
|
|
|
|
|
|
2021-02-15 11:06:40 +05:00
|
|
|
const load = async () => {
|
2021-02-12 16:26:11 +05:00
|
|
|
db.notes.init().then(() => {
|
|
|
|
|
init = true;
|
2021-02-16 16:11:10 +05:00
|
|
|
dispatch({type: Actions.NOTES});
|
|
|
|
|
dispatch({type: Actions.FAVORITES});
|
2021-02-15 11:06:40 +05:00
|
|
|
// if (!animation) {
|
|
|
|
|
dispatch({type: Actions.LOADING, loading: false});
|
|
|
|
|
// }
|
2021-02-12 16:26:11 +05:00
|
|
|
});
|
2021-02-15 11:06:40 +05:00
|
|
|
eSendEvent(eOpenSideMenu);
|
|
|
|
|
SettingsService.setAppLoaded();
|
|
|
|
|
setOpacity(false);
|
|
|
|
|
await sleep(150);
|
2021-02-12 16:26:11 +05:00
|
|
|
Animated.timing(opacityV, {
|
|
|
|
|
toValue: 0,
|
2021-02-15 11:06:40 +05:00
|
|
|
duration: 150,
|
2021-02-12 16:26:11 +05:00
|
|
|
easing: Easing.out(Easing.ease),
|
|
|
|
|
}).start();
|
|
|
|
|
Animated.timing(scaleV, {
|
|
|
|
|
toValue: 1,
|
2021-02-15 11:06:40 +05:00
|
|
|
duration: 150,
|
2021-02-12 16:26:11 +05:00
|
|
|
easing: Easing.out(Easing.ease),
|
|
|
|
|
}).start();
|
2021-02-15 11:06:40 +05:00
|
|
|
changeAppScale(1, 250);
|
|
|
|
|
await sleep(150);
|
2021-02-12 16:26:11 +05:00
|
|
|
setLoading(false);
|
|
|
|
|
animation = false;
|
2021-02-15 11:06:40 +05:00
|
|
|
//if (init) {
|
|
|
|
|
// dispatch({type: Actions.LOADING, loading: false});
|
|
|
|
|
//}
|
2021-02-12 16:26:11 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent('load_overlay', load);
|
2021-02-15 11:06:40 +05:00
|
|
|
onLoad();
|
2021-02-12 16:26:11 +05:00
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent('load_overlay', load);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
loading && (
|
|
|
|
|
<Animated.View
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: opacity ? colors.bg : 'rgba(0,0,0,0)',
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
zIndex: 999,
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
}}>
|
|
|
|
|
<Animated.View
|
|
|
|
|
onTouchStart={() => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
opacity: opacityV,
|
|
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
height: 10,
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
width: 100,
|
|
|
|
|
}}>
|
|
|
|
|
<AnimatedProgress
|
|
|
|
|
fill={colors.accent}
|
|
|
|
|
current={progress}
|
|
|
|
|
total={4}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|