Skip to content

Commit 2a8434c

Browse files
committed
add routers
1 parent 930bb20 commit 2a8434c

File tree

13 files changed

+673
-11
lines changed

13 files changed

+673
-11
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"zh": {
3+
"Home": {
4+
"tilte": "首页"
5+
},
6+
"Chat": {
7+
"tilte": "聊天"
8+
},
9+
"Login": {
10+
"tilte": "登录",
11+
"username": "用户名",
12+
"password": "密码"
13+
},
14+
"Register": {
15+
"tilte": "注册",
16+
"username": "用户名",
17+
"password": "密码"
18+
19+
}
20+
}
21+
}

example/app/routes/Chat/index.js

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
// /**
2+
// * Sample React Native App
3+
// * https://github.com/facebook/react-native
4+
// * @flow
5+
// */
6+
7+
import React, { Component } from 'react';
8+
import {
9+
AppRegistry,
10+
StyleSheet,
11+
Text,
12+
View,
13+
TouchableHighlight,
14+
NativeModules,
15+
requireNativeComponent,
16+
Alert,
17+
Dimensions,
18+
DeviceEventEmitter
19+
} from 'react-native';
20+
21+
var ReactNative = require('react-native');
22+
23+
import IMUI from 'aurora-imui-react-native'
24+
var InputView = IMUI.ChatInput;
25+
var MessageListView = IMUI.MessageList;
26+
const AuroraIController = IMUI.AuroraIMUIController;
27+
const window = Dimensions.get('window');
28+
29+
import Translations from '../../resource/Translations'
30+
31+
var themsgid = 1
32+
33+
function constructNormalMessage() {
34+
35+
var message = {}
36+
message.msgId = themsgid.toString()
37+
themsgid += 1
38+
message.status = "send_going"
39+
message.isOutgoing = true
40+
message.timeString = ""
41+
var user = {
42+
userId: "",
43+
displayName: "",
44+
avatarPath: ""
45+
}
46+
message.fromUser = user
47+
48+
return message
49+
}
50+
51+
export default class Chat extends Component {
52+
constructor(props) {
53+
super(props);
54+
this.state = { inputViewLayout: {width:window.width, height:86,}};
55+
56+
this.updateLayout = this.updateLayout.bind(this);
57+
}
58+
59+
componentDidMount() {
60+
AuroraIController.addMessageListDidLoadListener(() => {
61+
62+
var messages = []
63+
for(var i=0; i<14; i++){
64+
var message = constructNormalMessage()
65+
message.msgType = "text"
66+
message.text = "" + i
67+
AuroraIController.insertMessagesToTop([message])
68+
}
69+
AuroraIController.insertMessagesToTop(messages)
70+
});
71+
}
72+
73+
updateLayout(layout) {
74+
this.setState({inputViewLayout: layout})
75+
}
76+
77+
onAvatarClick = (message) => {
78+
console.log(message)
79+
}
80+
81+
onMsgClick = (message) => {
82+
console.log(message)
83+
}
84+
85+
onStatusViewClick = (message) => {
86+
console.log(message)
87+
message.status = 'send_succeed'
88+
message.fromUser.avatarPath = message.mediaPath
89+
AuroraIController.updateMessage(message)
90+
}
91+
92+
onBeginDragMessageList = () => {
93+
this.updateLayout({width:window.width, height:86,})
94+
AuroraIController.hidenFeatureView(true)
95+
}
96+
97+
onPullToRefresh = () => {
98+
console.log("on pull to refresh")
99+
}
100+
101+
onSendText = (text) => {
102+
103+
var message = constructNormalMessage()
104+
105+
message.msgType = "text"
106+
message.text = text
107+
message.timeString = 'fsdafafaf'
108+
109+
AuroraIController.appendMessages([message])
110+
AuroraIController.scrollToBottom(true)
111+
}
112+
113+
onTakePicture = (mediaPath) => {
114+
115+
var message = constructNormalMessage()
116+
message.msgType = "image"
117+
message.mediaPath = mediaPath
118+
119+
AuroraIController.appendMessages([message])
120+
AuroraIController.scrollToBottom(true)
121+
}
122+
123+
onStartRecordVoice = (e) => {
124+
console.log("on start record voice")
125+
}
126+
127+
onFinishRecordVoice = (mediaPath, duration) => {
128+
var message = constructNormalMessage()
129+
message.msgType = "voice"
130+
message.mediaPath = mediaPath
131+
message.duration = duration
132+
AuroraIController.appendMessages([message])
133+
}
134+
135+
onCancelRecordVoice = () => {
136+
console.log("on cancel record voice")
137+
}
138+
139+
onStartRecordVideo = () => {
140+
console.log("on start record video")
141+
}
142+
143+
onFinishRecordVideo = (mediaPath) => {
144+
var message = constructNormalMessage()
145+
146+
message.msgType = "video"
147+
message.mediaPath = mediaPath
148+
149+
AuroraIController.appendMessages([message])
150+
}
151+
152+
onSendGalleryFiles = (mediaFiles) => {
153+
154+
155+
/**
156+
* WARN: 这里返回的是原图,直接插入大会话列表会很大且耗内存.
157+
* 应该做裁剪操作后再插入到 messageListView 中,
158+
* 一般的 IM SDK 会提供裁剪操作,或者开发者手动进行裁剪。
159+
*
160+
* 代码用例不做裁剪操作。
161+
*/
162+
for(index in mediaFiles) {
163+
var message = constructNormalMessage()
164+
message.msgType = "image"
165+
message.mediaPath = mediaFiles[index].mediaPath
166+
AuroraIController.appendMessages([message])
167+
AuroraIController.scrollToBottom(true)
168+
}
169+
}
170+
171+
onSwitchToMicrophoneMode = () => {
172+
this.updateLayout({width:window.width, height:256,})
173+
}
174+
175+
onSwitchToGalleryMode = () => {
176+
this.updateLayout({width:window.width, height:256,})
177+
}
178+
179+
onSwitchToCameraMode = () => {
180+
this.updateLayout({width:window.width, height:256,})
181+
}
182+
183+
onShowKeyboard = (keyboard_height) => {
184+
var inputViewHeight = keyboard_height + 86
185+
this.updateLayout({width:window.width, height:inputViewHeight,})
186+
}
187+
188+
189+
onInitPress() {
190+
console.log('on click init push ');
191+
this.updateAction();
192+
}
193+
194+
render() {
195+
return (
196+
<View style={styles.container}>
197+
<MessageListView style={styles.messageList}
198+
onAvatarClick={this.onAvatarClick}
199+
onMsgClick={this.onMsgClick}
200+
onStatusViewClick={this.onStatusViewClick}
201+
onTapMessageCell={this.onTapMessageCell}
202+
onBeginDragMessageList={this.onBeginDragMessageList}
203+
onPullToRefresh={this.onPullToRefresh}
204+
avatarSize={{width:40,height:40}}
205+
sendBubbleTextSize={18}
206+
sendBubbleTextColor={"000000"}
207+
sendBubblePadding={{left:10,top:10,right:10,bottom:10}}
208+
/>
209+
<InputView style={this.state.inputViewLayout}
210+
onSendText={this.onSendText}
211+
onTakePicture={this.onTakePicture}
212+
onStartRecordVoice={this.onStartRecordVoice}
213+
onFinishRecordVoice={this.onFinishRecordVoice}
214+
onCancelRecordVoice={this.onCancelRecordVoice}
215+
onStartRecordVideo={this.onStartRecordVideo}
216+
onFinishRecordVideo={this.onFinishRecordVideo}
217+
onSendGalleryFiles={this.onSendGalleryFiles}
218+
onSwitchToMicrophoneMode={this.onSwitchToMicrophoneMode}
219+
onSwitchToGalleryMode={this.onSwitchToGalleryMode}
220+
onSwitchToCameraMode={this.onSwitchToCameraMode}
221+
onShowKeyboard={this.onShowKeyboard}
222+
/>
223+
</View>
224+
);
225+
}
226+
}
227+
228+
const styles = StyleSheet.create({
229+
container: {
230+
flex: 1,
231+
justifyContent: 'center',
232+
alignItems: 'center',
233+
backgroundColor: '#F5FCFF',
234+
},
235+
messageList: {
236+
backgroundColor: 'red',
237+
flex: 1,
238+
marginTop: 0,
239+
width: window.width,
240+
margin:0,
241+
},
242+
inputView: {
243+
backgroundColor: 'green',
244+
width: window.width,
245+
height:100,
246+
247+
},
248+
btnStyle: {
249+
marginTop: 10,
250+
borderWidth: 1,
251+
borderColor: '#3e83d7',
252+
borderRadius: 8,
253+
backgroundColor: '#3e83d7'
254+
}
255+
});
256+

example/app/routes/Home/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22

33
import React from 'react';
44
import ReactNative from 'react-native';
5+
import JMessage from 'jmessage-react-plugin';
6+
7+
import Translations from '../../resource/Translations'
58

69
const {
710
View,
811
Text,
912
TouchableHighlight,
1013
StyleSheet,
14+
Alert,
1115
} = ReactNative;
1216

13-
export default class MainActivity extends React.Component {
17+
export default class Home extends React.Component {
1418
constructor(props) {
1519
super(props);
1620
}
1721

22+
componentWillMount() {
23+
24+
}
25+
1826
render() {
19-
return (
20-
<Text >
21-
Get Platform List
22-
</Text> )
27+
return ( <Text >Home</Text> )
2328
}
2429
}

example/app/routes/Launch/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
import React from 'react';
4+
import ReactNative from 'react-native';
5+
import JMessage from 'jmessage-react-plugin';
6+
import Translations from '../../resource/Translations'
7+
8+
const {
9+
View,
10+
Text,
11+
TouchableHighlight,
12+
StyleSheet,
13+
Alert,
14+
} = ReactNative;
15+
16+
export default class Home extends React.Component {
17+
constructor(props) {
18+
super(props);
19+
}
20+
21+
componentWillMount() {
22+
const { navigate } = this.props.navigation;
23+
var params = {
24+
'appkey': "4f7aef34fb361292c566a1cd",
25+
'isOpenMessageRoaming': false,
26+
'isProduction': false,
27+
'channel': ""
28+
}
29+
JMessage.init(params)
30+
JMessage.getMyInfo((myInfo) => {
31+
if (myInfo.username) {
32+
navigate('Home')
33+
} else {
34+
navigate('Login')
35+
// navigate('Chat')
36+
}
37+
})
38+
39+
}
40+
41+
render() {
42+
return ( <View ></View> )
43+
}
44+
}

0 commit comments

Comments
 (0)