import {
NativeModules,
} from 'react-native';
import IMUI from 'aurora-imui-react-native';
var MessageList = IMUI.MessageList;
var ChatInput = IMUI.ChatInput;
const AuroraIMUIController = IMUI.AuroraIMUIController; // the IMUI controller, use it to operate messageList and ChatInput.
// add MessageList and ChatInput in render()
<MessageList />
<ChatInput />
Refer to iOS,Android example
For append/update/insert message to MessageList, you will use AuroraIMUIController
(Native Module) to send event to native.
param: [{message}]
Append message to bottom of the MessageList, the display order will be the same as the array of message's.
example:
var messages = [{
msgId: "1",
status: "send_going",
msgType: "text",
text: "Hello world",
isOutgoing: true,
fromUser: {
userId: "1",
displayName: "Ken",
avatarPath: "ironman"
},
timeString: "10:00"
}];
AuroraIMUIController.appendMessages(messages);
param: {message}
Update message, since the message status was changed, you should use this method to update your message.
example:
var message = {
msgId: "1",
status: "send_going",
msgType: "text",
text: text,
isOutgoing: true,
fromUser: {
userId: "1",
displayName: "Ken",
avatarPath: "ironman"
},
timeString: "10:00",
};
AuroraIMUIController.updateMessage(message);
param: [{message}]
Insert messages to the top of the MessageList, usually use this method to load history messages.
example:
var messages = [{
msgId: "1",
status: "send_succeed",
msgType: "text",
text: "This",
isOutgoing: true,
fromUser: {
userId: "1",
displayName: "Ken",
avatarPath: "ironman"
},
timeString: "10:00",
},{
msgId: "2",
status: "send_succeed",
msgType: "text",
text: "is",
isOutgoing: true,
fromUser: {
userId: "1",
displayName: "Ken",
avatarPath: "ironman"
},
timeString: "10:10",
},{
msgId: "3",
status: "send_succeed",
msgType: "text",
text: "example",
isOutgoing: true,
fromUser: {
userId: "1",
displayName: "Ken",
avatarPath: "ironman"
},
timeString: "10:20",
}];
AuroraIMUIController.insertMessagesToTop(messages);
Stop playing voice, including media players in ChatInput and MessageList.
example:
AuroraIMUIController.stopPlayVoice()
param: string
Remove message by message id.
example:
AuroraIMUIController.removeMessage("1")
Remove all messages.
example:
AuroraIMUIController.removeAllMessage()
-
addMessageListDidLoadListener(cb)
The initialization of
AuroraIMUIController
will finish beforeMessageListView
's,If you need do something toMessageListView
(such as append, insert, update and remove) you need to wait untillMessageListDidLoad
has been called.example:
AuroraIMUIController.addMessageListDidLoadListener(()=> { // do something ex: insert message to top })
-
removeMessageListDidLoadListener(cb)
Remove listener of
MessageListDidLoad
example:
AuroraIMUIController.removeMessageListDidLoadListener(cb)
PropTypes.function: ( message ) => { }
Fires when click avatar.
message param: { "message": message }
PropTypes.function: (message) => { }
Fires when click message bubble。
message param: { "message": message }
PropTypes.function: (message) => { }
Fires when click status view.
message param: { "message": message }
PropTypes.function: () => { }
Fires when pull MessageList to top, example usage: please refer sample's onPullToRefresh method.
In Android, you should put onPullToRefresh
in AndroidPtrLayout
, please refer sample/app/app.js for more detail.
PropTypes.function: () => { }
Fires when touch message list.
PropTypes.function
In android, if your want to define your chatting bubble, you need to put a drawable file in drawable folder, and that image file must be nine patch drawable file, see our example for detail.
In iOS, if your want to define your chatting bubble,you need to put a image file to you xcode,and specifies sendBubble.imageName or receiveBubble.imageName to image name.
PropTypes.object:{ imageName: string, padding: { left: number,top: number,right: number,bottom: number}
PropTypes.object:{ imageName: string, padding: { left: number,top: number,right: number,bottom: number}
PropTypes.string:
Set outgoing message's text color, sendBubbleTextColor="#000000"
.
PropTypes.string
Set incoming message's text color, sendBubbleTextColor="#000000"
.
PropTypes.number
Set outgoing message's text size.
PropTypes.number
Set incoming message's text size.
PropTypes.object: { left: number, top: number, right: number, bottom: number }
Set outgoing message's bubble padding.
PropTypes.object: { left: number, top: number, right: number, bottom: number }
Set incoming message's bubble padding.
PropTypes.number:
Set date text size of message.
PropTypes.string:
Set date text color of message, dateTextColor="#000000"
。
PropTypes.number:
Set date padding, note this padding type is not an object, means left, top, right and bottom padding is same.
PropTypes.object: { width: number, height: number }
This property including width and height.
Example: avatarSize = {width: 50, height: 50}
。
PropTypes.number:
Set fillet radius of avatar.
Example: avatarCornerRadius = {6}
。
PropTypes.bool:
Show sender's display name or not.
Example: isShowDisplayName={ture}
。
PropTypes.string:
Set messageList' background color. In Android, you should add this property in AndroidPtrlayout
.
<AndroidPtrLayout
ref="PtrLayout"
messageListBackgroundColor={"#f3f3f3"}
/>
Example: messageListBackgroundColor="#000000"
PropTypes.bool:
Show pull-to-refresh or not.
Example: isAllowPullToRefresh={ture}
。
PropTypes.string:
Set chatInput' background color.
Example: chatInputBackgroupColor="#000000"
PropTypes.bool:
Set the visibility of the select album button.
Example: showSelectAlbumBtn={true}
PropTypes.function: (text) => {}
After inputting text, fires when click send button, the text is the sending string(text: string
).
PropTypes.function: (result) => {}
After choosing picutres or videos, fires when click send button.
Result's type is {mediaFiles: [string]}
, including choosing files' path.
PropTypes.function: (result) => {}
Fires when click take picture button, result's type is {mediaPath: string}
。
PropTypes.function: () => {}
Fires when click record video button.
PropTypes.function: (result) => {}
Fires when finished recording video.
Result's type is {mediaPath: string, durationTime: number}
。
PropTypes.function:
Fires when click cancel record video button.
PropTypes.function:() => {}
Fires when click record audio button.
PropTypes.function: (result) => {}
After finishing recording audio, fires when finger left from screen,
Result's type is {mediaPath: string, duration: number}
。
PropTypes.function:() => {}
Fires when finger move to cancel record zone, and left from screen.
PropTypes.function: () => {}
Fires when click microphone button in menu.
PropTypes.function: () => {}
Fires when click picture button in menu.
PropTypes.function: () => {}
Fires when click camera button in menu.
PropTypes.function: () => {}
Fires when click emoji button in menu.
PropTypes.function: ({width: number, height: number}) => {}
Fires when ChantInput's size change。
PropTypes.function: (Android only)
Fires when click input view.
PropTypes.function: () => {}
Fires when click select album button(you can through showSelectAlbumBtn change the visibility )