fix delay on first load

This commit is contained in:
ammarahm-ed
2021-04-19 12:13:42 +05:00
parent 49880e5e9d
commit 43ce44d546
3 changed files with 52 additions and 48 deletions

View File

@@ -17,13 +17,10 @@ import {
eUnSubscribeEvent,
} from './src/services/EventManager';
import SettingsService from './src/services/SettingsService';
import { editing } from './src/utils';
import {db} from './src/utils/DB';
import {eDispatchAction, eOpenSideMenu} from './src/utils/Events';
import {MMKV} from './src/utils/mmkv';
import { tabBarRef } from './src/utils/Refs';
import EditorRoot from './src/views/Editor/EditorRoot';
import { setNoteOnly } from './src/views/Editor/Functions';
let initStatus = false;
const App = () => {
@@ -48,9 +45,11 @@ const App = () => {
eSendEvent(eOpenSideMenu);
SplashScreen.hide();
await db.init();
console.log('db is ready');
let requireIntro = await MMKV.getItem('introCompleted');
loadDefaultNotes();
console.log('loaded default note');
if (!requireIntro) {
await loadDefaultNotes();
await MMKV.setItem(
'askForRating',
JSON.stringify({
@@ -86,7 +85,7 @@ const App = () => {
})();
}, []);
const _dispatch = (data) => {
const _dispatch = data => {
dispatch(data);
};
@@ -98,6 +97,7 @@ const App = () => {
}, []);
const loadMainApp = () => {
console.log('status on init', initStatus);
if (initStatus) {
SettingsService.setAppLoaded();
eSendEvent('load_overlay');
@@ -107,6 +107,7 @@ const App = () => {
async function loadDefaultNotes() {
try {
console.log('creating note');
const isCreated = await MMKV.getItem('defaultNoteCreated');
if (isCreated) return;
const notes = await http.get(
@@ -114,6 +115,7 @@ const App = () => {
);
if (!notes) return;
for (let note of notes) {
console.log('getting content');
const content = await http.get(note.mobileContent);
await db.notes.add({
title: note.title,
@@ -122,9 +124,11 @@ const App = () => {
content: {type: 'tiny', data: content},
});
}
console.log('default note created');
await MMKV.setItem('defaultNoteCreated', 'yes');
dispatch({type: Actions.ALL});
} catch (e) {
console.log(e);
console.log(e, 'loading note on welcome');
}
}

View File

@@ -83,7 +83,7 @@ export const RootView = React.memo(
<ContextMenu />
<DummyText />
<DialogManager />
<Splash />
</>
);
},

View File

@@ -7,7 +7,7 @@ import {Actions} from '../../provider/Actions';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
eUnSubscribeEvent
} from '../../services/EventManager';
import { editing } from '../../utils';
import { changeContainerScale, ContainerScale } from '../../utils/Animations';
@@ -16,7 +16,7 @@ import {eOpenRateDialog, eOpenSideMenu} from '../../utils/Events';
import { MMKV } from '../../utils/mmkv';
import { tabBarRef } from '../../utils/Refs';
import { sleep } from '../../utils/TimeUtils';
import {setNoteOnly} from '../../views/Editor/Functions';
import SplashScreen from '../SplashScreen';
const scaleV = new Animated.Value(0.95);
const opacityV = new Animated.Value(1);
@@ -27,6 +27,7 @@ const AppLoader = ({onLoad}) => {
const [opacity, setOpacity] = useState(true);
const load = async value => {
console.log('loading called here');
if (value === 'hide') {
setLoading(true);
opacityV.setValue(1);
@@ -34,7 +35,6 @@ const AppLoader = ({onLoad}) => {
}
let appState = await MMKV.getItem('appState');
if (appState) {
appState = JSON.parse(appState);
if (!appState.movedAway && Date.now() < appState.timestamp + 3600000) {
editing.isRestoringState = true;
@@ -86,8 +86,7 @@ const AppLoader = ({onLoad}) => {
};
}, []);
return (
loading && (
return loading ? (
<Animated.View
style={{
backgroundColor: opacity ? colors.bg : 'rgba(0,0,0,0)',
@@ -120,7 +119,8 @@ const AppLoader = ({onLoad}) => {
</View>
</Animated.View>
</Animated.View>
)
) : (
<SplashScreen />
);
};