From 8ec66ea41513d2bc5a0a87ddca03b66c56b836e7 Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Wed, 25 Sep 2024 15:39:39 +0530 Subject: [PATCH] fix the back button usage for android --- app/components/post_draft/draft_input/index.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/components/post_draft/draft_input/index.tsx b/app/components/post_draft/draft_input/index.tsx index a78093b66c..e20940d596 100644 --- a/app/components/post_draft/draft_input/index.tsx +++ b/app/components/post_draft/draft_input/index.tsx @@ -8,8 +8,9 @@ import {type LayoutChangeEvent, Platform, ScrollView, View, Keyboard, DeviceEven import Animated, {Easing, runOnJS, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; import {type Edge, SafeAreaView} from 'react-native-safe-area-context'; +import {popTopScreen} from '@app/screens/navigation'; import {EmojiIndicesByAlias, Emojis} from '@app/utils/emoji'; -import {Events, General} from '@constants'; +import {Events, General, Screens} from '@constants'; import {MENTIONS_REGEX} from '@constants/autocomplete'; import {PostPriorityType} from '@constants/post'; import {useServerUrl} from '@context/server'; @@ -279,9 +280,13 @@ export default function DraftInput({ if (Platform.OS === 'android') { const backAction = () => { - setIsEmojiPickerOpen(false); - setIsEmojiSearchFocused(false); - return true; + if (isEmojiPickerOpen) { + setIsEmojiPickerOpen(false); + setIsEmojiSearchFocused(false); + return true; + } + popTopScreen(Screens.CHANNEL); + return false; }; backHandler = BackHandler.addEventListener('hardwareBackPress', backAction); @@ -289,7 +294,7 @@ export default function DraftInput({ return () => { backHandler?.remove(); }; - }, []); + }, [isEmojiPickerOpen]); const animatedStyle = useAnimatedStyle(() => { return {