Skip to content

Commit 6e78bb4

Browse files
authored
Merge pull request #257 from sendbird/fix/resolve-android-api-35-keyboard-avoid
[CLNP-7507] fix: improve keyboard handling when using button navigation on API 35
2 parents 4991aa3 + 837606c commit 6e78bb4

File tree

1 file changed

+24
-4
lines changed
  • packages/uikit-react-native/src/components/ChannelInput

1 file changed

+24
-4
lines changed

packages/uikit-react-native/src/components/ChannelInput/index.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect, useMemo, useState } from 'react';
22
import {
3+
Keyboard,
34
KeyboardAvoidingView,
45
Platform,
56
StyleProp,
@@ -94,10 +95,10 @@ export type ChannelInputProps = {
9495
};
9596

9697
const AUTO_FOCUS = Platform.select({ ios: false, android: true, default: false });
97-
const isAndroidApi35 = Platform.OS === 'android' && Platform.Version >= 35;
98+
const isAndroidApi35Plus = Platform.OS === 'android' && Platform.Version >= 35;
9899
const KEYBOARD_AVOID_VIEW_BEHAVIOR = Platform.select({
99100
ios: 'padding' as const,
100-
android: isAndroidApi35 ? ('padding' as const) : undefined,
101+
android: isAndroidApi35Plus ? ('padding' as const) : undefined,
101102
default: undefined,
102103
});
103104

@@ -121,7 +122,9 @@ const ChannelInput = (props: ChannelInputProps) => {
121122
* For older Android versions, we manually subtract the safe area bottom padding to avoid overlapping with system UI.
122123
* See: https://developer.android.com/develop/ui/views/layout/edge-to-edge
123124
*/
124-
const keyboardVerticalOffset = isAndroidApi35 ? keyboardAvoidOffset : -safeArea.paddingBottom + keyboardAvoidOffset;
125+
const keyboardVerticalOffset = isAndroidApi35Plus
126+
? keyboardAvoidOffset
127+
: -safeArea.paddingBottom + keyboardAvoidOffset;
125128
const { colors, typography } = useUIKitTheme();
126129
const { sbOptions, mentionManager } = useSendbirdChat();
127130

@@ -158,6 +161,23 @@ const ChannelInput = (props: ChannelInputProps) => {
158161
onChangeText(replace(text, searchStringRange.start, searchStringRange.end, mentionedMessageText), { user, range });
159162
};
160163

164+
const [keyboardShown, setKeyboardShown] = useState(false);
165+
166+
useEffect(() => {
167+
const keyboardDidShow = () => setKeyboardShown(true);
168+
const keyboardDidHide = () => setKeyboardShown(false);
169+
170+
const showSubscription = Keyboard.addListener('keyboardDidShow', keyboardDidShow);
171+
const hideSubscription = Keyboard.addListener('keyboardDidHide', keyboardDidHide);
172+
173+
return () => {
174+
showSubscription.remove();
175+
hideSubscription.remove();
176+
};
177+
}, []);
178+
179+
const shouldShowSafeAreaBottom = !isAndroidApi35Plus || (isAndroidApi35Plus && !keyboardShown);
180+
161181
if (!props.shouldRenderInput) {
162182
return <SafeAreaBottom height={safeArea.paddingBottom} />;
163183
}
@@ -204,7 +224,7 @@ const ChannelInput = (props: ChannelInputProps) => {
204224
/>
205225
)}
206226
</View>
207-
{!isAndroidApi35 && <SafeAreaBottom height={safeArea.paddingBottom} />}
227+
{shouldShowSafeAreaBottom && <SafeAreaBottom height={safeArea.paddingBottom} />}
208228
</View>
209229
</KeyboardAvoidingView>
210230
{mentionAvailable && props.SuggestedMentionList && (

0 commit comments

Comments
 (0)