From 654fc227d11b61d8bb9015004484a62520a7764e Mon Sep 17 00:00:00 2001 From: xuwenyang Date: Fri, 12 Jul 2019 23:53:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug:=201.=20=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=BA=95=E6=A0=8F=E2=80=98=E9=A6=96=E9=A1=B5=E2=80=99?= =?UTF-8?q?=E5=92=8C=E2=80=98=E5=85=B3=E6=B3=A8=E2=80=99=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=8B=A5=E5=88=97=E8=A1=A8=E5=B7=B2=E7=BD=AE=E9=A1=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E5=88=B7=E6=96=B0=E5=88=97=E8=A1=A8=202.=20=E6=97=A5?= =?UTF-8?q?=E8=AE=B0=E7=BC=96=E8=BE=91=E9=A1=B5=E7=9A=84=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=A1=86=E9=BB=98=E8=AE=A4=E9=80=89=E4=B8=AD=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/diary/diaryList.js | 13 ++++++++++++ src/page/FollowPage.js | 12 ++++++++++- src/page/WritePage.js | 36 ++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index a73facc..5056830 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -53,6 +53,15 @@ export default class DiaryList extends Component { } scrollToTop() { + if(!this.scrollY) { + this.scrollY = 0; + } + + if(this.scrollY <= 10) { + this.refresh(); + return; + } + this.list.scrollToOffset({ offset: 0 }); @@ -263,6 +272,10 @@ export default class DiaryList extends Component { onEndReachedThreshold={2} onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null} + + onScroll={(event) => { + this.scrollY = event.nativeEvent.contentOffset.y; + }} > diff --git a/src/page/FollowPage.js b/src/page/FollowPage.js index 3827505..494a98e 100644 --- a/src/page/FollowPage.js +++ b/src/page/FollowPage.js @@ -52,10 +52,20 @@ export default class FollowPage extends Component { }); } + componentDidMount() { + this.bottomTabEventListener = Navigation.events().registerBottomTabSelectedListener( + ({ selectedTabIndex, unselectedTabIndex }) => { + if(selectedTabIndex == unselectedTabIndex && selectedTabIndex == 1) { + this.diaryList.scrollToTop(); + } + } + ); + } + render() { return ( - this.list = r} + this.diaryList = r} dataSource={this.dataSource} {...this.props} diff --git a/src/page/WritePage.js b/src/page/WritePage.js index 4ca9d1c..cc7fa97 100644 --- a/src/page/WritePage.js +++ b/src/page/WritePage.js @@ -100,6 +100,7 @@ export default class WritePage extends Component { componentDidMount() { this.loadNotebook(); + this.contentInput.focus(); this.notebookListener = DeviceEventEmitter.addListener(Event.updateNotebooks, (param) => { this.loadNotebook(true); @@ -111,6 +112,7 @@ export default class WritePage extends Component { } openModal() { + this.contentInput.blur(); this.setState({modalVisible: true}); if(this.state.notebooks.length == 0) { @@ -120,15 +122,14 @@ export default class WritePage extends Component { } } - closeModal(showKeyboard = true) { - this.contentInput.blur(); + closeModal(showKeyboard = true, callback) { Animated.parallel([ Animated.timing( this.state.fadeAnimOpacity, { toValue: 0, duration: 350, - easing: Easing.out(Easing.cubic) + easing: Easing.out(Easing.linear) } ), Animated.timing( @@ -136,26 +137,35 @@ export default class WritePage extends Component { { toValue: 0, duration: 350, - easing: Easing.out(Easing.cubic) + easing: Easing.out(Easing.linear) } ) ]).start(({finished}) => { - this.setState({modalVisible: false}); if(!finished) { return; } - if(showKeyboard) { - setTimeout(() => this.contentInput.focus(), 100); - } + + this.setState({modalVisible: false}, () => { + setTimeout(() => { + if(showKeyboard) { + this.contentInput.focus() + } else { + if(typeof callback == 'function') { + callback(); + } + } + }, 100); + }); }); } _onCreateNotebook() { - this.closeModal(false); - Navigation.push(this.props.componentId, { - component: { - name: 'NotebookEdit' - } + this.closeModal(false, () => { + Navigation.push(this.props.componentId, { + component: { + name: 'NotebookEdit' + } + }); }); }