最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to customize react-native-gifted-chat in React Native 0.61 - Stack Overflow

programmeradmin4浏览0评论

Just wanted to share.

I was finding it difficult to customize the default UI for this package. The official documentation wasn't that helpful.

Luckily, I was able to solve it.

See answer

Just wanted to share.

I was finding it difficult to customize the default UI for this package. The official documentation wasn't that helpful.

Luckily, I was able to solve it.

See answer

Share Improve this question edited Feb 13, 2020 at 12:30 michael_vons asked Feb 13, 2020 at 10:44 michael_vonsmichael_vons 1,0601 gold badge11 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

Make your imports

import {GiftedChat, InputToolbar,...} from 'react-native-gifted-chat'

Customizing the InputToolbar

Note: InputToolbar must be imported since we want to customize it

Create a function called customInputToolbar that will return the custom UI

const customtInputToolbar = props => {
  return (
    <InputToolbar
      {...props}
      containerStyle={{
        backgroundColor: "white",
        borderTopColor: "#E8E8E8",
        borderTopWidth: 1,
        padding: 8
      }}
    />
  );
};

Note: props must be an argument.

Tip: Since all props for the InputToolbar were not listed in the official github page (https://github.com/FaridSafi/react-native-gifted-chat), you can Cmd + Left Click on the InputToolbar tag while in your editor. This will navigate you to the source file within which all props are listed. Be careful not to edit anything !!

Include the renderInputToolbar as a prop in the GiftedChat component

<GiftedChat
    messages={chatMessages.messages}
    onSend={messages => sendMessage(messages)}
    renderInputToolbar={props => customtInputToolbar(props)}
    ...
 />

Note: Remember to pass props as an argument to the function. Without this, the UI will not display

You're done !!

Customizing the SystemMessage component or using an absolutely custom UI

Include SystemMessage in your import

Create a function called customSystemMessage

  const customSystemMessage = props => {
    return (
      <View style={styles.ChatMessageSytemMessageContainer}>
        <Icon name="lock" color="#9d9d9d" size={16} />
        <Text style={styles.ChatMessageSystemMessageText}>
          Your chat is secured. Remember to be cautious about what you share
          with others.
        </Text>
      </View>
    );
  };

Include renderSystemMessage as a prop in your GiftedChat component

You're done

Hope this helps!

发布评论

评论列表(0)

  1. 暂无评论