11import React , { useEffect , useMemo , useState } from 'react' ;
22import {
3+ Keyboard ,
34 KeyboardAvoidingView ,
45 Platform ,
56 StyleProp ,
@@ -94,10 +95,10 @@ export type ChannelInputProps = {
9495} ;
9596
9697const 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 ;
9899const 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