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' + } + }); }); }