写这个组件是在几个月前,那时候是由于老大讲RN项目APP的通信聊天部分后面有可能本身实现,让我那时候尝试着搞下Android通信聊天UI实现的部分,在这期间,找了很多的Android原生项目:蘑菇街的TeamTalk,ChatDemo,EmojiChat,考虑到扩展性与改造复杂度,选择了学习融云 IM 界面组件。其实一直想写这个项目介绍,学习须要思考与总结,若是学了之后没有总结或者思考,慢慢地时间会磨平他们。html
AuroraChat 是个基于融云UI库的即时通信(IM)RN UI组件。react
本 UI 组件提供了消息列表、输入视图等经常使用组件,支持常见的消息类型:文字、图片、语音等。android
支持 Android,暂不支持iOS 平台。git
能够基于本 UI 库实现的功能:github
当前支持展现与输入的消息类型:react-native
当前提供的组件:服务器
import {DeviceEventEmitter} from "react-native"; import ChatView from "../rychatview";
ChatView网络
加载消息列表UI,须要传递必定格式的消息对象布局
message
对象格式:message = { // text message "type": "text", "own": false,//是否为当前用户 "content": "发送文本内容", "ts": "发送时间", "uid": "当前用户id", "msgid": "消息uid", "senduserinfo": "发送者信息" } message = { // image message "type": "image", "own": false,//是否为当前用户 "content": "图片URL", "ts": "发送时间", "uid": "当前用户id", "msgid": "消息uid", "senduserinfo": "发送者信息" } message = { // voice message "type": "voice", "own": false,//是否为当前用户 "duration": "50",//时长 单位:秒 "content": "语音URL", "ts": "发送时间", "uid": "当前用户id", "msgid": "消息uid", "senduserinfo": "发送者信息" } message = { // chatInfo message "userid": "用户id", "name": "昵称", "portraitUri": "头像URL", "chattype": "聊天类型",//群组 私聊 "targetid": "目标id" }
PropTypes.object:登陆聊天服务器后设置初始化学习
curChatInfo: { "userid": "1001", "name": "golike", "portraitUri":"http://img0.imgtn.bdimg.com/it/u=651843754,4204488972&fm=213&gp=0.jpg", "chattype": "priv", "targetid": "1002" }
PropTypes.bool:下拉刷新的标识符
PropTypes.function: () => {//从新网络请求 }
监听来自原生的不一样消息
componentDidMount() { //设置来自原生的消息的监听 this.subscription = DeviceEventEmitter.addListener('uploadMsg', this.onUpdateMessage); } componentWillUnmount() { //移除监听器 this.subscription.remove(); }
PropTypes.function:加载历史消息
historyMsgs = [ 前面消息类型中的消息,*,...] (historyMsgs) => {//链接消息服务器成功后获取的历史消息列表,发送给原生};
PropTypes.function:
(msg) => {//从js构造文本数据发送给原生};
PropTypes.function:未实现
(msg) => {//从js构造富文本数据发送给原生};
PropTypes.function:
(msg) => {//从js构造图片数据发送给原生};
PropTypes.function:
(msg) => {//从js构造语音数据发送给原生};