Skip to content

Commit 3dbd622

Browse files
authored
Merge pull request #261 from sendbird/fix/revert-keyboard-avoidance-android-api35
[CLNP-7537] revert: improve keyboard avoidance behavior for Android API 35+
2 parents b53e439 + 9b27ce9 commit 3dbd622

File tree

1 file changed

+6
-36
lines changed
  • packages/uikit-react-native/src/components/ChannelInput

1 file changed

+6
-36
lines changed

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

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useMemo, useState } from 'react';
22
import {
3-
Keyboard,
43
KeyboardAvoidingView,
54
Platform,
65
StyleProp,
@@ -95,12 +94,7 @@ export type ChannelInputProps = {
9594
};
9695

9796
const AUTO_FOCUS = Platform.select({ ios: false, android: true, default: false });
98-
const isAndroidApi35Plus = Platform.OS === 'android' && Platform.Version >= 35;
99-
const KEYBOARD_AVOID_VIEW_BEHAVIOR = Platform.select({
100-
ios: 'padding' as const,
101-
android: isAndroidApi35Plus ? ('padding' as const) : undefined,
102-
default: undefined,
103-
});
97+
const KEYBOARD_AVOID_VIEW_BEHAVIOR = Platform.select({ ios: 'padding' as const, default: undefined });
10498

10599
// FIXME(iOS): Dynamic style does not work properly when typing the CJK. (https://github.com/facebook/react-native/issues/26107)
106100
// To workaround temporarily, change the key for re-mount the component.
@@ -115,16 +109,6 @@ const ChannelInput = (props: ChannelInputProps) => {
115109

116110
const safeArea = useSafeAreaPadding(['top', 'left', 'right', 'bottom']);
117111

118-
// Android API 35+ keyboard avoidance handling
119-
/**
120-
* Android API 35+ introduced edge-to-edge layouts, which changed how keyboard avoidance should be handled.
121-
* For API 35+, the system manages insets automatically, so we use the provided keyboardAvoidOffset directly.
122-
* For older Android versions, we manually subtract the safe area bottom padding to avoid overlapping with system UI.
123-
* See: https://developer.android.com/develop/ui/views/layout/edge-to-edge
124-
*/
125-
const keyboardVerticalOffset = isAndroidApi35Plus
126-
? keyboardAvoidOffset
127-
: -safeArea.paddingBottom + keyboardAvoidOffset;
128112
const { colors, typography } = useUIKitTheme();
129113
const { sbOptions, mentionManager } = useSendbirdChat();
130114

@@ -161,30 +145,16 @@ const ChannelInput = (props: ChannelInputProps) => {
161145
onChangeText(replace(text, searchStringRange.start, searchStringRange.end, mentionedMessageText), { user, range });
162146
};
163147

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-
181148
if (!props.shouldRenderInput) {
182149
return <SafeAreaBottom height={safeArea.paddingBottom} />;
183150
}
184151

185152
return (
186153
<>
187-
<KeyboardAvoidingView keyboardVerticalOffset={keyboardVerticalOffset} behavior={KEYBOARD_AVOID_VIEW_BEHAVIOR}>
154+
<KeyboardAvoidingView
155+
keyboardVerticalOffset={-safeArea.paddingBottom + keyboardAvoidOffset}
156+
behavior={KEYBOARD_AVOID_VIEW_BEHAVIOR}
157+
>
188158
<View
189159
style={{
190160
paddingStart: safeArea.paddingStart,
@@ -224,7 +194,7 @@ const ChannelInput = (props: ChannelInputProps) => {
224194
/>
225195
)}
226196
</View>
227-
{shouldShowSafeAreaBottom && <SafeAreaBottom height={safeArea.paddingBottom} />}
197+
<SafeAreaBottom height={safeArea.paddingBottom} />
228198
</View>
229199
</KeyboardAvoidingView>
230200
{mentionAvailable && props.SuggestedMentionList && (

0 commit comments

Comments
 (0)