2021-02-25 12:16:38 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
|
|
|
|
import {View} from 'react-native';
|
|
|
|
|
import Animated, {Easing} from 'react-native-reanimated';
|
|
|
|
|
import AnimatedProgress from 'react-native-reanimated-progress-bar';
|
|
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {Actions} from '../../provider/Actions';
|
|
|
|
|
import {
|
|
|
|
|
eSendEvent,
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
|
|
|
|
} from '../../services/EventManager';
|
2021-04-10 08:48:11 +05:00
|
|
|
import { editing } from '../../utils';
|
2021-02-25 12:16:38 +05:00
|
|
|
import {changeContainerScale, ContainerScale} from '../../utils/Animations';
|
2021-03-01 14:53:37 +05:00
|
|
|
import {db} from '../../utils/DB';
|
2021-04-06 13:26:26 +05:00
|
|
|
import {eOpenRateDialog, eOpenSideMenu} from '../../utils/Events';
|
2021-04-03 14:06:40 +05:00
|
|
|
import {MMKV} from '../../utils/mmkv';
|
|
|
|
|
import {tabBarRef} from '../../utils/Refs';
|
2021-03-01 14:53:37 +05:00
|
|
|
import {sleep} from '../../utils/TimeUtils';
|
2021-04-17 12:49:41 +05:00
|
|
|
import { setNoteOnly } from '../../views/Editor/Functions';
|
2021-02-25 12:16:38 +05:00
|
|
|
|
|
|
|
|
const scaleV = new Animated.Value(0.95);
|
|
|
|
|
const opacityV = new Animated.Value(1);
|
|
|
|
|
const AppLoader = ({onLoad}) => {
|
|
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const colors = state.colors;
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const [opacity, setOpacity] = useState(true);
|
|
|
|
|
|
2021-04-10 08:48:11 +05:00
|
|
|
const load = async value => {
|
2021-03-01 14:53:37 +05:00
|
|
|
if (value === 'hide') {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
opacityV.setValue(1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (value === 'show') {
|
2021-04-03 14:06:40 +05:00
|
|
|
opacityV.setValue(0);
|
2021-03-01 14:53:37 +05:00
|
|
|
setLoading(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 12:16:38 +05:00
|
|
|
eSendEvent(eOpenSideMenu);
|
|
|
|
|
setOpacity(false);
|
2021-02-26 02:49:47 +05:00
|
|
|
await sleep(2);
|
2021-02-25 12:16:38 +05:00
|
|
|
Animated.timing(opacityV, {
|
|
|
|
|
toValue: 0,
|
|
|
|
|
duration: 150,
|
|
|
|
|
easing: Easing.out(Easing.ease),
|
|
|
|
|
}).start();
|
2021-02-26 02:49:47 +05:00
|
|
|
changeContainerScale(ContainerScale, 1, 600);
|
2021-02-25 12:16:38 +05:00
|
|
|
await sleep(150);
|
|
|
|
|
setLoading(false);
|
2021-04-17 12:49:41 +05:00
|
|
|
|
2021-02-25 12:16:38 +05:00
|
|
|
animation = false;
|
2021-04-10 08:48:11 +05:00
|
|
|
await db.notes.init();
|
|
|
|
|
dispatch({type: Actions.NOTES});
|
|
|
|
|
dispatch({type: Actions.FAVORITES});
|
|
|
|
|
dispatch({type: Actions.LOADING, loading: false});
|
|
|
|
|
eSendEvent(eOpenSideMenu);
|
2021-04-06 13:26:26 +05:00
|
|
|
let askForRating = await MMKV.getItem('askForRating');
|
|
|
|
|
if (askForRating !== 'never' || askForRating !== 'completed') {
|
|
|
|
|
askForRating = JSON.parse(askForRating);
|
2021-04-09 12:26:57 +05:00
|
|
|
if (askForRating?.timestamp < Date.now()) {
|
2021-04-06 13:26:26 +05:00
|
|
|
eSendEvent(eOpenRateDialog);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-25 12:16:38 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent('load_overlay', load);
|
|
|
|
|
onLoad();
|
|
|
|
|
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,
|
|
|
|
|
}}>
|
2021-03-01 14:53:37 +05:00
|
|
|
<AnimatedProgress fill={colors.accent} current={4} total={4} />
|
2021-02-25 12:16:38 +05:00
|
|
|
</View>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AppLoader;
|