105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import {View} from 'react-native';
|
|
import {Center, Heading, Spinner, HStack} from '@gluestack-ui/themed';
|
|
import {animated, useSpring} from '@react-spring/native';
|
|
import {SafeAreaView} from 'react-native-safe-area-context';
|
|
import {useSelector} from 'react-redux';
|
|
import {RootState, store} from '@redux/store';
|
|
import {useEffect} from 'react';
|
|
|
|
import {initAppData} from '@helper/appData';
|
|
import {appStatus} from '@configs/appNonSaveVar';
|
|
import {appNonSaveVarActions} from '@configs/appNonSaveVarReducer';
|
|
import BigDataManager from '@helper/storage/BigDataManager';
|
|
|
|
const AnimationView = animated(View);
|
|
|
|
function onAppStart() {
|
|
initAppData().then(() => {
|
|
BigDataManager.initDatabase()
|
|
.then(() => {
|
|
console.log('finish');
|
|
setTimeout(() => {
|
|
store.dispatch(
|
|
appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING),
|
|
);
|
|
}, 0);
|
|
})
|
|
.catch(err => {
|
|
console.error("Database Error! Can't start App :(");
|
|
});
|
|
|
|
//store.dispatch(actions.loadPreferences(appVar));
|
|
});
|
|
}
|
|
|
|
function StartHelper() {
|
|
const currentAppStatus = useSelector(
|
|
(state: RootState) => state.nonSaveVariables.appStatus,
|
|
);
|
|
|
|
const lang = useSelector((state: RootState) => state.appVariables.lang);
|
|
const theme = useSelector(
|
|
(state: RootState) => state.appVariables.preferences.theme,
|
|
);
|
|
|
|
const [motionProps, api] = useSpring(
|
|
() => ({
|
|
from: {
|
|
translateX: -150,
|
|
width: 4,
|
|
opacity: 1,
|
|
},
|
|
}),
|
|
[],
|
|
);
|
|
|
|
useEffect(() => {
|
|
api.start({
|
|
to: [
|
|
{
|
|
translateX: 150,
|
|
width: 4,
|
|
opacity: 1,
|
|
},
|
|
{
|
|
translateX: -150,
|
|
width: 4,
|
|
opacity: 1,
|
|
},
|
|
],
|
|
loop: true,
|
|
});
|
|
}, []);
|
|
|
|
useEffect(onAppStart, []);
|
|
|
|
if (currentAppStatus === appStatus.APP_RUNNING) return null;
|
|
|
|
return (
|
|
<SafeAreaView style={[{flex: 1, backgroundColor: '#26263f'}]}>
|
|
<Center height={'100%'}>
|
|
<AnimationView
|
|
style={{
|
|
height: 100,
|
|
position: 'absolute',
|
|
|
|
backgroundColor: '#931278',
|
|
borderRadius: 8,
|
|
|
|
width: motionProps.width,
|
|
opacity: motionProps.opacity,
|
|
transform: [{translateX: motionProps.translateX}, {translateY: 5}],
|
|
}}
|
|
/>
|
|
<Heading style={{color: '#fff'}}>{lang.appName}</Heading>
|
|
|
|
<HStack marginTop={5} justifyContent="center">
|
|
<Spinner color="#931278" size="large" />
|
|
</HStack>
|
|
</Center>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
export default StartHelper;
|