reduce delay in capturing intent and loading app

This commit is contained in:
ammarahm-ed
2020-12-22 12:38:31 +05:00
parent f9585dc995
commit 436bafa7b8
8 changed files with 51 additions and 61 deletions

View File

@@ -13,6 +13,7 @@ import * as RNIap from 'react-native-iap';
import {enabled} from 'react-native-privacy-snapshot';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import SplashScreen from 'react-native-splash-screen';
import {RootView} from './initializer.root';
import {useTracked} from './src/provider';
import {Actions} from './src/provider/Actions';
import Backup from './src/services/Backup';
@@ -43,16 +44,14 @@ import {
eOpenPendingDialog,
eOpenProgressDialog,
eOpenSideMenu,
eStartSyncer,
refreshNotesPage,
} from './src/utils/Events';
import {MMKV} from './src/utils/mmkv';
import {tabBarRef} from './src/utils/Refs';
import {sleep} from './src/utils/TimeUtils';
import {getNote} from './src/views/Editor/Functions';
import {getIntent, getNote, setIntent} from './src/views/Editor/Functions';
const {ReceiveSharingIntent} = NativeModules;
let AppRootView = require('./initializer.root').RootView;
let Sentry = null;
let appIsInitialized = false;
let intentOnAppLoadProcessed = false;
@@ -106,6 +105,8 @@ const onAppStateChanged = async (state) => {
function loadIntent(event) {
if (event) {
setIntent();
console.log(event, getIntent());
eSendEvent(eOnLoadNote, event);
tabBarRef.current?.goToPage(1);
Navigation.closeDrawer();
@@ -131,9 +132,7 @@ const onNetworkStateChanged = (netInfo) => {
};
const App = () => {
const [, dispatch] = useTracked(),
[init, setInit] = useState(true),
[intent, setIntent] = useState(false);
const [, dispatch] = useTracked();
let subsriptionSuccessListerner;
let subsriptionErrorListener;
@@ -157,7 +156,6 @@ const App = () => {
EV.unsubscribe('user:loggedOut', onLogout);
EV.unsubscribe('db:sync', partialSync);
EV.unsubscribe('user:checkStatus', PremiumService.onUserStatusCheck);
eUnSubscribeEvent(eStartSyncer, startSyncer);
eUnSubscribeEvent(eDispatchAction, (type) => {
dispatch(type);
});
@@ -272,8 +270,8 @@ const App = () => {
};
const loadMainApp = () => {
dispatch({type: Actions.INTENT_MODE, state: false});
dispatch({type: Actions.ALL});
AppRootView = require('./initializer.root').RootView;
setCurrentUser().then(console.log).catch(console.log);
Backup.checkAndRun().then((r) => r);
sleep(500).then(() => (appIsInitialized = true));
@@ -314,17 +312,20 @@ const App = () => {
let isIntent = false;
IntentService.getIntent()
.then(() => {
AppRootView = require('./initializer.intent').IntentView;
setInit(false);
IntentService.check((event) => {
SplashScreen.hide();
loadIntent(event);
intentOnAppLoadProcessed = true;
dispatch({type: Actions.ALL});
setIntent(true);
isIntent = true;
dispatch({type: Actions.INTENT_MODE, state: true});
ReceiveSharingIntent.clearFileNames();
});
})
.catch((e) => console.log)
.finally(() => {
if (!isIntent) {
dispatch({type: Actions.INTENT_MODE, state: false});
ReceiveSharingIntent.clearFileNames();
intentOnAppLoadProcessed = true;
loadMainApp();
@@ -372,8 +373,7 @@ const App = () => {
return (
<SafeAreaProvider>
{intent ? <AppRootView /> : null}
{init && !intent ? <AppRootView /> : null}
<RootView />
</SafeAreaProvider>
);
};

View File

@@ -1,25 +0,0 @@
import React from 'react';
import {DialogManager} from './src/components/DialogManager';
import {DummyText} from './src/components/DummyText';
import {Toast} from './src/components/Toast';
import {useTracked} from './src/provider';
import {EditorWrapper} from './src/views/Editor/EditorWrapper';
export const IntentView = () => {
const [state] = useTracked();
const {colors} = state;
return (
<>
<EditorWrapper
dimensions={{
width: '100%',
height: '100%',
}}
/>
<Toast />
<DummyText />
<DialogManager colors={colors} />
</>
);
};

View File

@@ -55,11 +55,20 @@ const onChangeTab = async (obj) => {
export const RootView = () => {
const [state] = useTracked();
const {colors} = state;
const {colors, intentMode} = state;
return (
<>
{intentMode ? (
<EditorWrapper
dimensions={{
width: '100%',
height: '100%',
}}
/>
) : (
<NavigationStack component={AppStack} />
)}
<Toast />
<ContextMenu />
<DummyText />

View File

@@ -32,5 +32,6 @@ export const Actions = {
FULLSCREEN:"fullscreen",
DEVICE_MODE:"deviceMode",
MENU_PINS:"menuPins",
LAST_SYNC:"lastSynced"
LAST_SYNC:"lastSynced",
INTENT_MODE: "intentMode"
};

View File

@@ -82,5 +82,6 @@ export const defaultState = {
},
keyword: [],
menuPins:[],
lastSynced:"Never"
lastSynced:"Never",
intentMode:true
};

View File

@@ -266,6 +266,13 @@ export const reducer = (state, action) => {
menuPins: action.lastSync,
};
}
case Actions.INTENT_MODE: {
return {
...state,
intentMode: action.state,
};
}
default:
throw new Error('unknown action type');
}

View File

@@ -121,7 +121,7 @@ const EditorHeader = () => {
};
const _onBackPress = async () => {
if (getIntent() && sideMenuRef.current === null) {
if (sideMenuRef.current === null) {
if (tapCount > 0) {
tapCount = 0;
setIntent(false);

View File

@@ -155,13 +155,12 @@ function clearNote() {
let currentEditingTimer = null;
export async function loadNote(item) {
export const loadNote = async (item) => {
editing.currentlyEditing = true;
post('blur');
if (item && item.type === 'new') {
intent = false;
if (intent) return;
await clearEditor();
clearNote();
noteEdited = false;
@@ -177,11 +176,11 @@ export async function loadNote(item) {
await clearEditor();
clearNote();
id = null;
intent = true;
content = {
data: item.data,
type: 'delta',
};
intent = true;
if (webviewInit) {
await loadNoteInEditor();
}
@@ -193,9 +192,8 @@ export async function loadNote(item) {
await loadNoteInEditor();
}
updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: item.id});
}
}
};
export function setIntentNote(item) {
id = null;
@@ -277,7 +275,7 @@ export async function clearEditor() {
});
saveCounter = 0;
clearNote();
intent = false;
//intent = false;
}
function checkIfContentIsSavable() {
@@ -382,7 +380,7 @@ export async function saveNote(canPost = true) {
}
saveCounter++;
} else {
await db.vault.save({
let note = await db.vault.save({
title,
content: {
type: content.type,
@@ -424,7 +422,7 @@ async function loadEditorState() {
}
}
} else {
IntentService.check((event) => {
/* IntentService.check((event) => {
if (event) {
intent = true;
eSendEvent(eOnLoadNote, event);
@@ -433,7 +431,7 @@ async function loadEditorState() {
} else {
eSendEvent('nointent');
}
});
}); */
}
}
@@ -443,18 +441,17 @@ const loadNoteInEditor = async () => {
if (!webviewInit) return;
saveCounter = 0;
if (intent) {
await sleep(1500);
post('delta', content.data);
intent = true;
intent = false;
await saveNote();
} else if (note?.id) {
post('title', title);
intent = false;
setColors();
post('delta', content.data);
await sleep(100);
await sleep(10);
post('dateEdited', timeConverter(note.dateEdited));
}
await sleep(50);
await sleep(10);
post('clearHistory');
};