Skip to content

Commit

Permalink
added function for back button closes emoji picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-Dabade committed Sep 24, 2024
1 parent ec3d0db commit 23b49ba
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/components/post_draft/draft_input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import GraphemeSplitter from 'grapheme-splitter';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {useIntl} from 'react-intl';
import {type LayoutChangeEvent, Platform, ScrollView, View, Keyboard, DeviceEventEmitter} from 'react-native';
import {type LayoutChangeEvent, Platform, ScrollView, View, Keyboard, DeviceEventEmitter, BackHandler, type NativeEventSubscription} from 'react-native';
import Animated, {Easing, runOnJS, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import {type Edge, SafeAreaView} from 'react-native-safe-area-context';

Expand Down Expand Up @@ -274,6 +274,23 @@ export default function DraftInput({
}
}, [isEmojiSearchFocused]);

useEffect(() => {
let backHandler: NativeEventSubscription | undefined;

if (Platform.OS === 'android') {
const backAction = () => {
setIsEmojiPickerOpen(false);
setIsEmojiSearchFocused(false);
return true;
};

backHandler = BackHandler.addEventListener('hardwareBackPress', backAction);
}
return () => {
backHandler?.remove();
};
}, []);

const animatedStyle = useAnimatedStyle(() => {
return {
height: height.value,
Expand Down

0 comments on commit 23b49ba

Please sign in to comment.