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
-
- Props Event
- Props customizable style
- sendBubble
- receiveBubble
- sendBubbleTextColor
- receiveBubbleTextColor
- sendBubbleTextSize
- receiveBubbleTextSize
- sendBubblePadding
- receiveBubblePadding
- dateTextSize
- dateTextColor
- datePadding
- dateBackgroundColor
- dateCornerRadius
- avatarSize
- avatarCornerRadius
- isShowDisplayName
- isShowIncomingDisplayName
- isShowOutgoingDisplayName
- displayNameTextSize
- displayNameTextColor
- displayNamePadding
- eventTextColor
- eventTextSize
- eventTextPadding
- eventBackgroundColor
- eventCornerRadius
- eventTextLineHeight
- messageListBackgroundColor
- maxBubbleWidth
- messageTextLineHeight
- isAllowPullToRefresh
-
- Props customizable style
- Props Event
- onSendText
- onSendGalleryFile
- onTakePicture
- onStartRecordVideo
- onFinishRecordVideo
- onCancelRecordVideo
- onStartRecordVoice
- onFinishRecordVoice
- onCancelRecordVoice
- onSwitchToMicrophoneMode
- onSwitchToGalleryMode
- onSwitchToCameraMode
- onSwitchToEmojiMode
- onSizeChange
- onFullScreen
- onRecoverScreen
- onTouchEditText
- onClickSelectAlbum
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. The messages to be inserted must be sorted chronologically.
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()
hiden inputView's featureView.
example:
AuroraIMUIController.hidenFeatureView()
-
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.object: { left: number, top: number, right: number, bottom: number}
Set date padding.
Example: datePadding={left: 5, top: 10, right: 5, bottom: 10}
PropTypes.string
Set the background color of date.
Example: dateBackgroundColor={"#cecece"}
PropTypes.number
Set the background corner radius of date.
Example: dateCornerRadius={5}
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 display name or not.
Example: isShowDisplayName={ture}
。
PropTypes.bool:
Set Show receiver's display name or not.
Example: isShowIncomingDisplayName={true}
PropTypes.bool:
Set show sender's display name or not.
Example: isShowOutgoingDisplayName={false}
PropTypes.number
Set the text size of display name.
Example: displayNameTextSize={14}
PropTypes.string
Set the color of display name.
Example: displayNameTextColor={"#cecece"}
PropTypes.object = {left: number, top: number, right: number, bottom: number}
Set padding of display name.
Example: displayNamePadding={left: 5, top: 0, right: 0, bottom: 5}
PropTypes.string:
Set messageList' background color.
Example: messageListBackgroundColor={"#f3f3f3"}
PropTypes.number
Set the max width of message bubble, the value is the percentage of mobile's width.
Example: maxBubbleWidth={0.7}
means set the max bubble width to 70% of mobile width.
PropTypes.number
Set text message's line spacing.
Example: messageTextLineHeight={5}
PropTypes.bool:
Show pull-to-refresh or not.
Example: isAllowPullToRefresh={ture}
。
PropTypes.string:
Customize ChatInput feature and layout。
Eample:
// You can put item into ChatInput's left/right/bottom part,(Can be repeated but not recommended)
customLayoutItems={{
left: ['voice'],
right: ['send'],
bottom: ['gallery','emoji','camera','camera']
}}
// if you don't put element in left/right/bottom ChatInput will hidden the part.
customLayoutItems={{
left: ['voice'],
right: ['send']
}}
PropTypes.string:
Set chatInput' background color.
Example: chatInputBackgroupColor="#000000"
PropTypes.bool:
Set the visibility of the select album button.
Example: showSelectAlbumBtn={true}
PropTypes.bool:
Set the visibility of the record video button.
Example: showRecordVideoBtn={true}
PropTypes.object: {left: number, top: number, right: number, bottom: number}
Set the padding of TextInput.
Example: inputPadding={left:5, top:0, right:5, bottom:0}
PropTypes.string: {"#xxxxxx"}
Set the text color of TextInput.
Example: inputTextColor={"#808080"}
PropTypes.numbser: {numbser}
Set the text size of TextInput.
Example: inputTextSize={14}
PropTypes.number:{numbser}
Set the text line spacing of TextInput.
Example: inputTextLineHeight={2}
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: () => {}
Fires when camera switch into full screen mode.
PropTypes.function: () => {}
Fires when camera cancel full screen mode.
PropTypes.function: (Android only)
Fires when click input view text input.
PropTypes.function: () => {}
(Android only)
Fires when click select album button(you can through showSelectAlbumBtn change the visibility )