|
1 | 1 | # ReactNative IMUI |
2 | 2 | 项目fork自 jpush 的 [Aurora IMUI](https://github.com/jpush/aurora-imui/tree/master/ReactNative) |
3 | 3 |
|
4 | | - |
5 | 4 | ## 使用 |
6 | | -当前提供的组件: |
| 5 | +参考[demo](https://github.com/reactnativecomponent/react-native-chat-demo) |
| 6 | +## 安装 |
| 7 | + |
| 8 | +``` |
| 9 | +npm install aurora-imui-react-native --save |
| 10 | +react-native link |
| 11 | +``` |
| 12 | + |
| 13 | +如果 link 安卓失败,需要手动修改一下 `settings.gradle` 中的引用路径: |
| 14 | + |
| 15 | +``` |
| 16 | +include ':app', ':aurora-imui-react-native' |
| 17 | +project(':aurora-imui-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/aurora-imui-react-native/ReactNative/android') |
| 18 | +``` |
| 19 | + |
| 20 | +然后在 app 的 `build.gradle`中引用: |
| 21 | + |
| 22 | +``` |
| 23 | +dependencies { |
| 24 | + compile project(':aurora-imui-react-native') |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +**注意事项(Android):我们使用了 support v4, v7 25.3.1 版本,因此需要将你的 build.gradle 中 buildToolsVersion 及 compiledSdkVersion 改为 25 以上。可以参考 sample 的配置。** |
| 29 | + |
| 30 | +## 配置 |
| 31 | + |
| 32 | +- ### Android |
| 33 | + |
| 34 | + - 引入 Package: |
| 35 | + |
| 36 | + > MainApplication.java |
| 37 | +
|
| 38 | + ``` |
| 39 | + import cn.jiguang.imui.messagelist.ReactIMUIPackage; |
| 40 | + ... |
| 41 | +
|
| 42 | + @Override |
| 43 | + protected List<ReactPackage> getPackages() { |
| 44 | + return Arrays.<ReactPackage>asList( |
| 45 | + new MainReactPackage(), |
| 46 | + new ReactIMUIPackage() |
| 47 | + ); |
| 48 | + } |
| 49 | + ``` |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +- ### iOS |
| 57 | + |
| 58 | + - PROJECT -> TARGETS -> Build Settings -> Enable Bitcode Set to No |
| 59 | + - Find PROJECT -> TARGETS -> General -> Embedded Binaries and add RCTAuroraIMUI.framework |
| 60 | + - 构建你的项目之前,你需要构建 RCTAuroraIMUI.framework |
| 61 | + |
| 62 | +## 数据格式 |
| 63 | + |
| 64 | +使用 MessageList,你需要定义 `message` 对象和 `fromUser` 对象。 |
| 65 | + |
| 66 | +- `message` 对象格式: |
| 67 | + |
| 68 | +**status 必须为以下四个值之一: "send_succeed", "send_failed", "send_going", "download_failed",如果没有定义这个属性, 默认值是 "send_succeed".** |
| 69 | + |
| 70 | + ``` |
| 71 | + message = { // text message |
| 72 | + msgId: "msgid", |
| 73 | + status: "send_going", |
| 74 | + msgType: "text", |
| 75 | + isOutgoing: true, |
| 76 | + text: "text" |
| 77 | + fromUser: {} |
| 78 | +} |
| 79 | +
|
| 80 | +message = { // image message |
| 81 | + msgId: "msgid", |
| 82 | + msgType: "image", |
| 83 | + isOutGoing: true, |
| 84 | + progress: "progress string" |
| 85 | + mediaPath: "image path" |
| 86 | + fromUser: {} |
| 87 | +} |
| 88 | +
|
| 89 | +
|
| 90 | +message = { // voice message |
| 91 | + msgId: "msgid", |
| 92 | + msgType: "voice", |
| 93 | + isOutGoing: true, |
| 94 | + duration: number, // 注意这个值有用户自己设置时长,单位秒 |
| 95 | + mediaPath: "voice path" |
| 96 | + fromUser: {} |
| 97 | +} |
| 98 | +
|
| 99 | +message = { // video message |
| 100 | + msgId: "msgid", |
| 101 | + status: "send_failed", |
| 102 | + msgType: "video", |
| 103 | + isOutGoing: true, |
| 104 | + druation: number |
| 105 | + mediaPath: "voice path" |
| 106 | + fromUser: {} |
| 107 | +} |
| 108 | +
|
| 109 | +message = { // event message |
| 110 | + msgId: "msgid", |
| 111 | + msgType: "event", |
| 112 | + text: "the event text" |
| 113 | +} |
| 114 | + ``` |
| 115 | + |
| 116 | +- `fromUser` 对象格式: |
| 117 | + |
| 118 | + ``` |
| 119 | + fromUser = { |
| 120 | + userId: "" |
| 121 | + displayName: "" |
| 122 | + avatarPath: "avatar image path" |
| 123 | + } |
| 124 | + ``` |
7 | 125 |
|
8 | | -### React Native |
9 | | -- [AuroraIMUI](./ReactNative/README_zh.md) |
|
0 commit comments