Skip to content

Commit

Permalink
fix the back button usage for android
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-Dabade committed Sep 25, 2024
1 parent 23b49ba commit 8ec66ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/components/post_draft/draft_input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -279,17 +280,21 @@ 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);
}
return () => {
backHandler?.remove();
};
}, []);
}, [isEmojiPickerOpen]);

const animatedStyle = useAnimatedStyle(() => {
return {
Expand Down

0 comments on commit 8ec66ea

Please sign in to comment.