From 2ae6e48627fe1359793952da10b27c1e8d5bbd90 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Mon, 23 Nov 2020 12:32:33 +0500 Subject: [PATCH] do not load dialogs on init in memory --- .../src/components/AddNotebookDialog/index.js | 18 +- .../src/components/AddTopicDialog/index.js | 4 +- apps/mobile/src/components/Dialog/index.js | 14 +- .../src/components/DialogManager/index.js | 169 ++++++++++-------- .../src/components/ExportDialog/index.js | 4 +- .../src/components/JumpToDialog/index.js | 22 +-- .../src/components/LoginDialog/index.js | 9 +- .../src/components/MergeEditor/index.js | 4 +- .../src/components/MoveNoteDialog/index.js | 23 +-- .../src/components/ProgressDialog/index.js | 4 +- .../src/components/RecoveryKeyDialog/index.js | 41 +++-- .../src/components/RestoreDialog/index.js | 4 +- .../src/components/ResultDialog/index.js | 22 +-- .../mobile/src/components/SortDialog/index.js | 49 +++-- .../src/components/VaultDialog/index.js | 8 +- apps/mobile/src/services/SettingsService.js | 3 +- apps/mobile/src/views/Editor/index.js | 18 +- 17 files changed, 216 insertions(+), 200 deletions(-) diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js index d6d55102b..051f78c00 100644 --- a/apps/mobile/src/components/AddNotebookDialog/index.js +++ b/apps/mobile/src/components/AddNotebookDialog/index.js @@ -215,21 +215,6 @@ export class AddNotebookDialog extends React.Component { topics: prevTopics, }); this.currentInputValue = null; - /* if (prevTopics[this.prevIndex + 1] && forward) { - this.prevIndex = this.prevIndex + 1; - this.prevItem = prevTopics[this.prevIndex]; - this.currentInputValue = this.prevItem; - this.topicInputRef.setNativeProps({ - text: null, - }); - this.topicInputRef.setNativeProps({ - text: prevTopics[this.prevIndex], - }); - this.setState({ - editTopic:true - }) - } else {} */ - if (this.state.editTopic) { this.topicInputRef.blur(); Keyboard.dismiss(); @@ -261,9 +246,10 @@ export class AddNotebookDialog extends React.Component { visible, topicInputFocused, } = this.state; + if (!visible) return null; return ( { this.titleRef.current?.focus(); }} - visible={visible} + visible={true} onRequestClose={this.close}> + { this.actionSheet._setModalVisible(); @@ -93,6 +96,11 @@ export class DialogManager extends Component { _hideActionSheet = () => { this.actionSheet._setModalVisible(); + sleep(200).then(() => { + this.setState({ + actionSheetVisible: false, + }); + }); }; _showMoveNote = () => { @@ -230,11 +238,11 @@ export class DialogManager extends Component { case 'delete': { if (this.state.item.locked) { openVault({ - item:this.state.item, - novault:true, - locked:true, - deleteNote:true, - }) + item: this.state.item, + novault: true, + locked: true, + deleteNote: true, + }); } else { this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type)); } @@ -246,28 +254,28 @@ export class DialogManager extends Component { } case 'novault': { openVault({ - item:this.state.item, - novault:false, - locked:true, - deleteNote:true, - }) + item: this.state.item, + novault: false, + locked: true, + deleteNote: true, + }); break; } case 'locked': { openVault({ - item:this.state.item, - novault:true, - locked:true, - }) + item: this.state.item, + novault: true, + locked: true, + }); break; } case 'unlock': { openVault({ - item:this.state.item, - novault:true, - locked:true, - permanant:true - }) + item: this.state.item, + novault: true, + locked: true, + permanant: true, + }); break; } case 'notebook': { @@ -300,68 +308,71 @@ export class DialogManager extends Component { let {actionSheetData, item, simpleDialog} = this.state; return ( <> - (this.actionSheet = ref)} - containerStyle={{ - backgroundColor: colors.bg, - width: DDS.isTab ? 500 : '100%', - alignSelf: 'center', - borderRadius: 10, - marginBottom: DDS.isTab ? 50 : 0, - }} - extraScroll={DDS.isTab ? 50 : 0} - indicatorColor={ - Platform.ios - ? hexToRGBA(colors.accent + '19') - : hexToRGBA(colors.shade) - } - premium={ - this.actionSheet._hideModal()} - offset={50} - /> - } - keyboardShouldPersistTaps="always" - delayActionSheetDraw={true} - delayActionSheetDrawTime={10} - footerAlwaysVisible={DDS.isTab} - footerHeight={DDS.isTab ? 20 : 10} - footerStyle={ - DDS.isTab - ? { - borderRadius: 10, - backgroundColor: colors.bg, - } - : null - } - initialOffsetFromBottom={1} - bounceOnOpen={false} - gestureEnabled={true} - onClose={() => { - translatePrem.setValue(-800) - this.onActionSheetHide(); - }}> - { - this.willRefresh = true; + {!this.state.actionSheetVisible ? null : ( + (this.actionSheet = ref)} + containerStyle={{ + backgroundColor: colors.bg, + width: DDS.isTab ? 500 : '100%', + alignSelf: 'center', + borderRadius: 10, + marginBottom: DDS.isTab ? 50 : 0, }} - hasColors={actionSheetData.colors} - hasTags={actionSheetData.colors} - overlayColor={ - colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)' + extraScroll={DDS.isTab ? 50 : 0} + indicatorColor={ + Platform.ios + ? hexToRGBA(colors.accent + '19') + : hexToRGBA(colors.shade) } - rowItems={actionSheetData.rowItems} - columnItems={actionSheetData.columnItems} - close={(value) => { - if (value) { - this.show = value; + premium={ + this.actionSheet._hideModal()} + offset={50} + /> + } + keyboardShouldPersistTaps="always" + delayActionSheetDraw={true} + delayActionSheetDrawTime={10} + footerAlwaysVisible={DDS.isTab} + footerHeight={DDS.isTab ? 20 : 10} + footerStyle={ + DDS.isTab + ? { + borderRadius: 10, + backgroundColor: colors.bg, + } + : null + } + initialOffsetFromBottom={1} + bounceOnOpen={false} + gestureEnabled={true} + onClose={() => { + translatePrem.setValue(-800); + this.onActionSheetHide(); + }}> + { + this.willRefresh = true; + }} + hasColors={actionSheetData.colors} + hasTags={actionSheetData.colors} + overlayColor={ + colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)' } - this.actionSheet._setModalVisible(); - }} - /> - + rowItems={actionSheetData.rowItems} + columnItems={actionSheetData.columnItems} + close={(value) => { + if (value) { + this.show = value; + } + this.actionSheet._setModalVisible(); + }} + /> + + )} + (this.simpleDialog = ref)} item={item} diff --git a/apps/mobile/src/components/ExportDialog/index.js b/apps/mobile/src/components/ExportDialog/index.js index 5b99d9b71..a30527aff 100644 --- a/apps/mobile/src/components/ExportDialog/index.js +++ b/apps/mobile/src/components/ExportDialog/index.js @@ -154,11 +154,11 @@ const ExportDialog = () => { }, ]; - return ( + return !visible ? null : ( } onRequestClose={close} - visible={visible}> + visible={true}> { }); }; - return ( + return !visible ? null : ( { loadOffsets(); }} onRequestClose={close} - visible={visible}> + visible={true}> { try { let res = await db.user.login(username.toLowerCase(), password); - } catch (e) { setTimeout(() => { ToastEvent.show(e.message, 'error', 'local'); @@ -146,7 +145,7 @@ const LoginDialog = () => { ToastEvent.show('Passwords do not match', 'error', 'local'); return false; } - + if (invalidEmail && invalidPassword && invalidUsername) { ToastEvent.show('Signup information is invalid', 'error', 'local'); return false; @@ -202,13 +201,13 @@ const LoginDialog = () => { } }; - return ( + return !visible ? null : ( { link.click(); }`; - return ( - + return !visible ? null : ( + { if (!newTopicTitle || newTopicTitle.trim().length === 0) { return ToastEvent.show('Title is required', 'error', 'local'); } - let res = await db.notebooks.notebook(expanded).topics.add(newTopicTitle); - dispatch({type: Actions.NOTEBOOKS}); dispatch({type: Actions.PINNED}); topicInput.current?.clear(); @@ -90,12 +81,12 @@ const MoveNoteDialog = () => { newTopicTitle = null; }; - return ( + return !visible ? null : ( { setVisible(false); }; - return ( - + return !visible ? null : ( + { + this.actionSheetRef.current?._setModalVisible(true); + }, + ); }; close = () => { this.actionSheetRef.current?._setModalVisible(false); + sleep(200).then(() => { + this.setState({ + visible: false, + }); + }); if (this.signup) { setTimeout(() => { eSendEvent(eOpenResultDialog, { @@ -122,6 +136,7 @@ class RecoveryKeyDialog extends React.Component { render() { const {colors} = this.props; + if (!this.state.visible) return null; return ( { setFiles(files); }; - return ( + return !visible? null : ( { setVisible(false); }; - return ( - + return !visible ? null : ( + { + actionSheet.current?._setModalVisible(true); + await this.getSettings(); + }, + ); } async getSettings() { @@ -41,6 +50,11 @@ class SortDialog extends React.Component { close() { actionSheet.current?._setModalVisible(false); + sleep(200).then(() => { + this.setState({ + visible: false, + }); + }); } async componentDidMount() { @@ -55,6 +69,9 @@ class SortDialog extends React.Component { render() { const {colors} = this.props; + + if (!this.state.visible) return null; + return ( { passInputRef.current?.focus(); }} onRequestClose={this.close} - visible={visible}> + visible={true}> ) : null} - {this.state.isBiometryAvailable && !this.state.fingerprintAccess && - (!this.state.biometricUnlock || !novault) ? ( + {this.state.isBiometryAvailable && + !this.state.fingerprintAccess && + (!this.state.biometricUnlock || !novault) ? ( { this.setState({ diff --git a/apps/mobile/src/services/SettingsService.js b/apps/mobile/src/services/SettingsService.js index d97f6b3eb..bd8635735 100644 --- a/apps/mobile/src/services/SettingsService.js +++ b/apps/mobile/src/services/SettingsService.js @@ -38,7 +38,8 @@ async function init() { sortSettings.sortOrder = settings.sortOrder; updateSize(); updateEvent({type: Actions.SETTINGS, settings: {...settings}}); - await setTheme(); + setTheme(); + return; } const setTheme = async () => { diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js index 14b8a27f7..e688f8967 100755 --- a/apps/mobile/src/views/Editor/index.js +++ b/apps/mobile/src/views/Editor/index.js @@ -1,11 +1,5 @@ -import React from 'react'; -import { - KeyboardAvoidingView, - Platform, - SafeAreaView, - TextInput, - View, -} from 'react-native'; +import React, { useEffect } from 'react'; +import {Platform, TextInput, View} from 'react-native'; import WebView from 'react-native-webview'; import {useTracked} from '../../provider'; import EditorHeader from './EditorHeader'; @@ -22,6 +16,10 @@ import { const Editor = () => { const [state] = useTracked(); const {colors, premiumUser} = state; + + useEffect(() => { + console.log('rendering editor'); + }) return ( <> { testID="editor" ref={EditorWebView} onError={(error) => console.log(error)} - onLoad={async () => await onWebViewLoad(premiumUser, colors)} + onLoad={async (event) => + await onWebViewLoad(premiumUser, colors, event) + } javaScriptEnabled={true} focusable={true} keyboardDisplayRequiresUserAction={false}