|
1 | | -# react-native-imui |
2 | | -react-native im ui |
| 1 | +## IMUI for React Native |
| 2 | + |
| 3 | +[中文文档](./README_zh.md) |
| 4 | + |
| 5 | +## InstallREADME_zh.md |
| 6 | + |
| 7 | +``` |
| 8 | +npm install react-native-imui --save |
| 9 | +react-native link |
| 10 | +``` |
| 11 | + |
| 12 | +If link Android failed, you need modify `settings.gradle`: |
| 13 | + |
| 14 | +``` |
| 15 | +include ':app', ':react-native-imui' |
| 16 | +project(':react-native-imui').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-imui/android') |
| 17 | +``` |
| 18 | + |
| 19 | +And add dependency in your app's `build.gradle`: |
| 20 | + |
| 21 | +``` |
| 22 | +dependencies { |
| 23 | + compile project(':react-native-imui') |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +## Configuration |
| 30 | + |
| 31 | +- ### Android |
| 32 | + |
| 33 | + - Add Package: |
| 34 | + |
| 35 | + > MainApplication.java |
| 36 | +
|
| 37 | + ``` |
| 38 | + @Override |
| 39 | + protected List<ReactPackage> getPackages() { |
| 40 | + return Arrays.<ReactPackage>asList( |
| 41 | + new MainReactPackage(), |
| 42 | + new ReactIMUIPackage() |
| 43 | + ); |
| 44 | + } |
| 45 | + ``` |
| 46 | + |
| 47 | + - import IMUI from 'react-native-imui'; |
| 48 | + |
| 49 | + |
| 50 | +- ### iOS |
| 51 | + |
| 52 | + - PROJECT -> TARGETS -> Build Settings -> Enable Bitcode Set to No |
| 53 | + - Find PROJECT -> TARGETS -> General -> Embedded Binaries and add RNTAuroraIMUI.framework |
| 54 | + - Before build you project ,you should build RNTAuroraIMUI.framework |
| 55 | + |
| 56 | +## Usage |
| 57 | +``` |
| 58 | + import IMUI from 'react-native-imui'; |
| 59 | + var MessageList = IMUI.MessageList; |
| 60 | + var ChatInput = IMUI.ChatInput; |
| 61 | + const AuroraIMUIModule = NativeModules.AuroraIMUIModule; |
| 62 | +``` |
| 63 | +Refer to iOS,Android example |
| 64 | +> [iOS Example usage](./sample/index.ios.js) |
| 65 | +> [Android Example usage](./sample/react-native-android/pages/chat_activity.js) |
| 66 | +## Data format |
| 67 | + |
| 68 | +By using MessageList, you need define `message` object and `fromUser` object. |
| 69 | + |
| 70 | +- message object format: |
| 71 | + |
| 72 | +** status must be one of the four values: "send_succeed", "send_failed", "send_going", "download_failed", |
| 73 | +if you haven't define this property, default value is "send_succeed".** |
| 74 | + |
| 75 | + ``` |
| 76 | + message = { // text message |
| 77 | + msgId: "msgid", |
| 78 | + status: "send_going", |
| 79 | + msgType: "text", |
| 80 | + isOutgoing: true, |
| 81 | + text: "text" |
| 82 | + fromUser: {} |
| 83 | +} |
| 84 | +
|
| 85 | +message = { // image message |
| 86 | + msgId: "msgid", |
| 87 | + msgType: "image", |
| 88 | + isOutGoing: true, |
| 89 | + progress: "progress string" |
| 90 | + mediaPath: "image path" |
| 91 | + fromUser: {} |
| 92 | +} |
| 93 | +
|
| 94 | +
|
| 95 | +message = { // voice message |
| 96 | + msgId: "msgid", |
| 97 | + msgType: "voice", |
| 98 | + isOutGoing: true, |
| 99 | + duration: number |
| 100 | + mediaPath: "voice path" |
| 101 | + fromUser: {} |
| 102 | +} |
| 103 | +
|
| 104 | +message = { // video message |
| 105 | + msgId: "msgid", |
| 106 | + status: "send_failed", |
| 107 | + msgType: "video", |
| 108 | + isOutGoing: true, |
| 109 | + druation: number |
| 110 | + mediaPath: "voice path" |
| 111 | + fromUser: {} |
| 112 | +} |
| 113 | + ``` |
| 114 | + |
| 115 | +- fromUser object format: |
| 116 | + |
| 117 | + ``` |
| 118 | + fromUser = { |
| 119 | + userId: "" |
| 120 | + displayName: "" |
| 121 | + avatarPath: "avatar image path" |
| 122 | + } |
| 123 | + ``` |
| 124 | + |
| 125 | + |
| 126 | + ## Event Handling |
| 127 | + |
| 128 | + ### MessageList Event |
| 129 | +- onAvatarClick {message: {message json}} :Fires when click avatar |
| 130 | + |
| 131 | +- onMsgClick {message: {message json} : Fires when click message bubble |
| 132 | + |
| 133 | +- onStatusViewClick {message: {message json}} Fires when click status view |
| 134 | + |
| 135 | +- onPullToRefresh Fires when pull MessageList to top, example usage: please refer sample's onPullToRefresh method. |
| 136 | + |
| 137 | + |
| 138 | +- onBeginDragMessageList (iOS only) |
| 139 | + |
| 140 | + ### MessageList append/update/insert message event: |
| 141 | + |
| 142 | + For append/update/insert message to MessageList, you will use `MsgListModule`(Native Module) to send event to native. |
| 143 | + |
| 144 | +- appendMessages([message]) |
| 145 | + |
| 146 | + example: |
| 147 | + |
| 148 | +``` |
| 149 | +var messages = [{ |
| 150 | + msgId: "1", |
| 151 | + status: "send_going", |
| 152 | + msgType: "text", |
| 153 | + text: "Hello world", |
| 154 | + isOutgoing: true, |
| 155 | + fromUser: { |
| 156 | + userId: "1", |
| 157 | + displayName: "Ken", |
| 158 | + avatarPath: "ironman" |
| 159 | + }, |
| 160 | + timeString: "10:00", |
| 161 | +}]; |
| 162 | +AuroraIMUIModule.appendMessages(messages); |
| 163 | +``` |
| 164 | + |
| 165 | +- updateMessage(message) |
| 166 | + |
| 167 | +example: |
| 168 | + |
| 169 | +``` |
| 170 | +var message = { |
| 171 | + msgId: "1", |
| 172 | + status: "send_going", |
| 173 | + msgType: "text", |
| 174 | + text: text, |
| 175 | + isOutgoing: true, |
| 176 | + fromUser: { |
| 177 | + userId: "1", |
| 178 | + displayName: "Ken", |
| 179 | + avatarPath: "ironman" |
| 180 | + }, |
| 181 | + timeString: "10:00", |
| 182 | +}; |
| 183 | +AuroraIMUIModule.updateMessage(message); |
| 184 | +``` |
| 185 | + |
| 186 | +- insertMessagesToTop([message]) |
| 187 | + |
| 188 | + **Notice that the order of message array must be sorted in chronological order** |
| 189 | + |
| 190 | +example: |
| 191 | + |
| 192 | +``` |
| 193 | +var messages = [{ |
| 194 | + msgId: "1", |
| 195 | + status: "send_succeed", |
| 196 | + msgType: "text", |
| 197 | + text: "This", |
| 198 | + isOutgoing: true, |
| 199 | + fromUser: { |
| 200 | + userId: "1", |
| 201 | + displayName: "Ken", |
| 202 | + avatarPath: "ironman" |
| 203 | + }, |
| 204 | + timeString: "10:00", |
| 205 | + },{ |
| 206 | + msgId: "2", |
| 207 | + status: "send_succeed", |
| 208 | + msgType: "text", |
| 209 | + text: "is", |
| 210 | + isOutgoing: true, |
| 211 | + fromUser: { |
| 212 | + userId: "1", |
| 213 | + displayName: "Ken", |
| 214 | + avatarPath: "ironman" |
| 215 | + }, |
| 216 | + timeString: "10:10", |
| 217 | +},{ |
| 218 | + msgId: "3", |
| 219 | + status: "send_succeed", |
| 220 | + msgType: "text", |
| 221 | + text: "example", |
| 222 | + isOutgoing: true, |
| 223 | + fromUser: { |
| 224 | + userId: "1", |
| 225 | + displayName: "Ken", |
| 226 | + avatarPath: "ironman" |
| 227 | + }, |
| 228 | + timeString: "10:20", |
| 229 | +}]; |
| 230 | +AuroraIMUIModule.insertMessagesToTop(messages); |
| 231 | +``` |
| 232 | + |
| 233 | +## Style |
| 234 | + |
| 235 | +### MessageList custom style |
| 236 | + |
| 237 | +**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](https://developer.android.com/reference/android/graphics/drawable/NinePatchDrawable.html), see our example for detail.** |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | +**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. if you need to set the default avatar, you need put you default avatar image to you xcode,and adjust the image name to `defoult_header`,see our example for detail.** |
| 242 | + |
| 243 | +- sendBubble: PropTypes.object : |
| 244 | +``` |
| 245 | +// eg: |
| 246 | + { |
| 247 | + imageName:"inComing_bubble", |
| 248 | + padding:{left:10,top:10,right:15,bottom:10} |
| 249 | + } |
| 250 | +``` |
| 251 | + |
| 252 | +- receiveBubble: PropTypes.object, |
| 253 | + |
| 254 | +- sendBubbleTextColor: PropTypes.string, |
| 255 | + |
| 256 | +- receiveBubbleTextColor: PropTypes.string, |
| 257 | + |
| 258 | +- sendBubbleTextSize: PropTypes.number, |
| 259 | + |
| 260 | +- receiveBubbleTextSize: PropTypes.number, |
| 261 | + |
| 262 | + |
| 263 | +This Padding object includes four properties: left, top, right, bottom. |
| 264 | +``` |
| 265 | + // eg: |
| 266 | + { |
| 267 | + left: 5, |
| 268 | + top: 5, |
| 269 | + right: 15, |
| 270 | + bottom: 5 |
| 271 | + } |
| 272 | +``` |
| 273 | +- sendBubblePadding: PropTypes.object |
| 274 | + |
| 275 | +- receiveBubblePadding: PropTypes.object |
| 276 | + |
| 277 | +- dateTextSize: PropTypes.number, |
| 278 | + |
| 279 | +- dateTextColor: PropTypes.string, |
| 280 | + |
| 281 | +- datePadding: PropTypes.number -- This is a number property, means padding left/top/right/bottom value is same. |
| 282 | + |
| 283 | +Size object include width and height properties. |
| 284 | + |
| 285 | +- avatarSize: PropTypes.object -- Example: avatarSize = {width: 50, height: 50} |
| 286 | + |
| 287 | +- showDisplayName: PropTypes.bool, |
| 288 | + |
0 commit comments