From 6952c7b97c10bede9b93f39781f7406f86eb2793 Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Sun, 6 Dec 2020 14:25:14 +0800 Subject: [PATCH] feat: support confirming exiting app by Android back action --- src/ui/YooForumUI.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ui/YooForumUI.js b/src/ui/YooForumUI.js index 86b4099..053de93 100644 --- a/src/ui/YooForumUI.js +++ b/src/ui/YooForumUI.js @@ -10,6 +10,7 @@ import { Dimensions, Pressable, BackHandler, + ToastAndroid, } from 'react-native'; import YooForumTopic from '../component/YooForumTopic'; import YooReply from './YooReply'; @@ -85,6 +86,7 @@ export default class YooForumUI extends Component { translateX: new Animated.Value(0), currentReplies: [], replyTranslateY: new Animated.Value(0), + lastPressingBack: 0, }; this.replyRef = createRef(); this.showDetail = this.showDetail.bind(this); @@ -101,9 +103,15 @@ export default class YooForumUI extends Component { } handleAndroidBack() { - if (this.currentForumTopicUI){ + if (this.currentForumTopicUI) { this.hideDetail(); 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; } }