Browse Source

feat: support confirming exiting app by Android back action

dev 0.0.6a
kdxcxs 4 years ago
parent
commit
6952c7b97c
  1. 10
      src/ui/YooForumUI.js

10
src/ui/YooForumUI.js

@ -10,6 +10,7 @@ import {
Dimensions, Dimensions,
Pressable, Pressable,
BackHandler, BackHandler,
ToastAndroid,
} from 'react-native'; } from 'react-native';
import YooForumTopic from '../component/YooForumTopic'; import YooForumTopic from '../component/YooForumTopic';
import YooReply from './YooReply'; import YooReply from './YooReply';
@ -85,6 +86,7 @@ export default class YooForumUI extends Component {
translateX: new Animated.Value(0), translateX: new Animated.Value(0),
currentReplies: [], currentReplies: [],
replyTranslateY: new Animated.Value(0), replyTranslateY: new Animated.Value(0),
lastPressingBack: 0,
}; };
this.replyRef = createRef(); this.replyRef = createRef();
this.showDetail = this.showDetail.bind(this); this.showDetail = this.showDetail.bind(this);
@ -101,9 +103,15 @@ export default class YooForumUI extends Component {
} }
handleAndroidBack() { handleAndroidBack() {
if (this.currentForumTopicUI){ if (this.currentForumTopicUI) {
this.hideDetail(); this.hideDetail();
return true; return true;
} else if (new Date().getTime() - this.state.lastPressingBack <= 1000) {
BackHandler.exitApp();
} else {
this.setState({lastPressingBack: new Date().getTime()});
ToastAndroid.show('再按一次以退出Yoomooc', ToastAndroid.SHORT);
return true;
} }
} }

Loading…
Cancel
Save