From d1596501869c4e906e2571e39f5c79d80382d083 Mon Sep 17 00:00:00 2001 From: mx1700 Date: Sun, 4 Aug 2019 20:29:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E5=87=BA=E5=86=99=E6=97=A5=E8=AE=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=A4=BA=20&=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=86=99=E6=97=A5=E8=AE=B0=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=89=93=E5=BC=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page/EmptyPage.js | 74 +++++++++++++++++++------------------------ src/page/WritePage.js | 36 ++++++++++++--------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/page/EmptyPage.js b/src/page/EmptyPage.js index 02951a1..01a0ba8 100644 --- a/src/page/EmptyPage.js +++ b/src/page/EmptyPage.js @@ -23,57 +23,47 @@ export default class EmptyPage extends Component { componentDidMount() { this.navigationEventListener = Navigation.events().bindComponent(this); + this.bottomTabEventListener = Navigation.events().registerBottomTabSelectedListener(({ selectedTabIndex, unselectedTabIndex }) => { + if(selectedTabIndex === 2) { + Navigation.showModal({ + stack: { + children: [{ + component: { + name: 'Write', + passProps: { + text: 'stack with one child' + }, + bottomTabs: { + visible: false, + + // hide bottom tab for android + drawBehind: true, + animate: true + } + } + }] + } + }); + + setTimeout(() => { + Navigation.mergeOptions(this.props.componentId, { + bottomTabs: { + currentTabIndex: unselectedTabIndex + } + }); + }, 1000) + } + }); } componentWillUnmount() { this.navigationEventListener.remove(); + this.bottomTabEventListener.remove(); } componentDidAppear() { - let forword = true; - if(this.state.from == 'write') { - forword = false; - this.setState({from: ''}); - } - if(!forword) { - - Navigation.mergeOptions(this.props.componentId, { - bottomTabs: { - currentTabIndex: 4 - } - }); - - - } else { - Navigation.push(this.props.componentId, { - component: { - name: 'Write', - options: { - animations: { - push: { - enabled: false - }, - pop: { - enabled: false - } - }, - bottomTabs: { - visible: false, - - // hide bottom tab for android - drawBehind: true, - animate: true - } - }, - passProps: { - - } - } - }); - } - } diff --git a/src/page/WritePage.js b/src/page/WritePage.js index 18931a9..5790a5f 100644 --- a/src/page/WritePage.js +++ b/src/page/WritePage.js @@ -81,23 +81,19 @@ export default class WritePage extends Component { navigationButtonPressed({buttonId}) { if(buttonId == 'cancel') { - if(this.diary || this.topic) { - Navigation.pop(this.props.componentId); - - } else { - Navigation.setStackRoot(this.props.componentId, { - component: { - name: 'Empty', - options: { - bottomTabs: { - visible: true - } - }, - passProps: { - from: 'write' + if(this.state.content.length > 0) { + Alert.alert('提示', '日记还没保存,退出将删除日记内容', [ + { + text: '取消', onPress: () => {} + }, + { + text: '删除并退出', onPress: () => { + this.closePage(); } } - }); + ]); + } else { + this.closePage(); } } else if(buttonId == 'save') { @@ -105,6 +101,16 @@ export default class WritePage extends Component { } } + closePage() { + this.contentInput.blur(); + if (this.diary || this.topic) { + Navigation.pop(this.props.componentId); + + } else { + Navigation.dismissModal(this.props.componentId); + } + } + componentDidMount() { this.loadNotebook().then(notebookCount => { if(notebookCount > 0) {