简体   繁体   中英

Remove space between keyboard and composer in React-Native-Gifted-Chat

I'm using the react-native-gifted-chat package for my React Native application. Somehow there is a space between the composer and the keyboard, although I did not customise the GiftedChat.

Marked orange in the attached screenshot:

在此处输入图像描述

I already tried to customise the composer or any other component, with not effect.

install react-native-iphone-x-helper

and add these lines according to your code.

import { getBottomSpace } from 'react-native-iphone-x-helper';



<GiftedChat 
    bottomOffset={getBottomSpace()}
    ...
/>

i'm also facing same problem after some time i find this solution and it's work for me.

     <GiftedChat
                    isAnimated
                    messages={this.state.messages}
                    scrollToBottom={true}
                    renderUsernameOnMessage={true}
                    onSend={messages => this.onSend(messages)}
                    inverted={false}
                    isLoadingEarlier={true}
                    messagesContainerStyle={{ color: 'gray' }}
                    bottomOffset={0} // add this line and space is remove
                    renderBubble={props => {
                        return (
                            <Bubble
                                {...props}

                                textStyle={{
                                    right: {
                                        color: 'white',
                                    },
                                    left: {
                                        color: '#24204F',
                                    },
                                }}
                                wrapperStyle={{
                                    left: {
                                        backgroundColor: 'white',
                                    },
                                    right: {
                                        backgroundColor: "#ff3b00", // red
                                    },
                                }}
                            />
                        );
                    }}
                    renderInputToolbar={props => {
                        return (<InputToolbar {...props} containerStyle={{ backgroundColor: '#e2e2e2' }} />);
                    }}
                    user={{
                        _id: 1
                    }}
                />

hope this willl work for you bottomOffset={0} // add this line and space is remove

As found on the docs itself, simply get the insets:

const insets = useSafeAreaInsets();
<GiftedChat
   bottomOffset={insets.bottom}
   ...
 />

This will fix your issue dynamically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM