javascript - 如何在 React Native 0.61 中自定义 react-native-gifted-chat
问题描述
只是想分享。
我发现很难为这个包自定义默认 UI。官方文档没有那么有用。
幸运的是,我能够解决它。
查看答案
解决方案
进行进口
import {GiftedChat, InputToolbar,...} from 'react-native-gifted-chat'
自定义输入工具栏
注意:必须导入,因为我们要自定义它 InputToolbar
创建一个调用的函数,该函数customInputToolbar
将返回自定义 UI
const customtInputToolbar = props => {
return (
<InputToolbar
{...props}
containerStyle={{
backgroundColor: "white",
borderTopColor: "#E8E8E8",
borderTopWidth: 1,
padding: 8
}}
/>
);
};
注意:必须是参数。 props
提示:由于官方 github 页面 ( https://github.com/FaridSafi/react-native-gifted-chat )中没有列出 的所有道具,因此您可以在编辑器中的标签上。这会将您导航到列出所有道具的源文件。小心不要编辑任何东西!InputToolbar
Cmd + Left Click
InputToolbar
在组件中包含renderInputToolbar
作为道具GiftedChat
<GiftedChat
messages={chatMessages.messages}
onSend={messages => sendMessage(messages)}
renderInputToolbar={props => customtInputToolbar(props)}
...
/>
注意:记住要props
作为参数传递给函数。没有这个,UI 将不会显示
你完成了 !!
自定义 SystemMessage 组件或使用绝对自定义的 UI
包含SystemMessage
在您的导入中
创建一个名为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>
);
};
在组件中包含renderSystemMessage
作为道具GiftedChat
你完成了
希望这可以帮助!
推荐阅读
- javascript - 如何使用 javascript 在表单输入值中编写 cookie?
- javascript - 上传到dropzone(dropzone.js)的图片使用cropper.js进行裁剪,但发布时不显示裁剪的图片
- python - Clickhouse - 数据转换/解析
- javascript - 如何对使用 Node.js 和 Yeoman 创建的 Javascript Office 插件 (OneNote) 进行故障排除?
- android - Android kotlin 使用 ViewModelFactory 将动态参数/参数传递给 ViewModel
- javascript - Vanilla Javascript 在数组上使用函数,每个元素有多个值
- spring-boot - 通过过滤器/拦截器代理http请求的最直接方法是什么?
- opencv - 如何在opencv python中获取面部温度
- firebase - 如何在 Crashlytics/Flutter (Android) 中查看 Dart 代码堆栈跟踪而不是 Java 代码堆栈跟踪
- python - 在 Matplotlib lib 中创建 10 个不同的图形而不单独创建它们