Skip to content

Commit 7301e84

Browse files
committed
udpate example
1 parent ed427b9 commit 7301e84

File tree

5 files changed

+167
-22
lines changed

5 files changed

+167
-22
lines changed

example/app/routes/Home/ConversationList/index.js

Lines changed: 111 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const {
1515
Alert,
1616
TextInput,
1717
FlatList,
18-
Image
18+
Image,
19+
Modal,
1920
} = ReactNative;
2021

2122
class MyListItem extends React.PureComponent {
@@ -56,11 +57,37 @@ const styles = StyleSheet.create({
5657
height: 45,
5758
marginRight: 10,
5859
},
60+
61+
modalView: {
62+
    flex: 1,
63+
    justifyContent: 'center',
64+
alignItems: 'center',
65+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
66+
},
67+
modalContent: {
68+
width: 200,
69+
height: 150,
70+
    justifyContent: 'center',
71+
alignItems: 'center',
72+
backgroundColor: '#ffffff',
73+
},
74+
modalButton: {
75+
76+
}
5977
});
6078

6179
var count = 0
80+
6281
export default class ConversationList extends React.Component {
6382
static navigationOptions = {
83+
headerRight: <Button
84+
title="创建会话"
85+
onPress={
86+
({state}) => {
87+
Alert.alert('state', JSON.stringify(state.params))
88+
89+
}}
90+
/>,
6491
title: "会话",
6592
tabBarLabel: '会话',
6693
tabBarIcon: ({ tintColor }) => (
@@ -71,14 +98,26 @@ const styles = StyleSheet.create({
7198
),
7299
};
73100

101+
onCreateConversation() {
102+
// this.setState({isShowModal: true})
103+
Alert.alert("click","success")
104+
}
105+
74106
constructor(props) {
75107
super(props);
76108
this.state = {
77-
data: [{key:'a'}, {key:'b'}]
109+
data: [{key:'a'}, {key:'b'}],
110+
modalText: "",
111+
isShowModal: false,
78112
}
79-
this._onPress = this._onPress.bind(this)
113+
// this.onCreateConversation = this.onCreateConversation.bind(this)
114+
// this.props.navigation.setParams({ createConversastion: this.onCreateConversation });
80115
}
81116

117+
componentDidMount() {
118+
this.props.navigation.setParams({ createConversastion: this.onCreateConversation });
119+
this.props.navigation.setParams({ test: 'test' });
120+
}
82121
componentWillMount() {
83122
JMessage.getConversations((result) => {
84123

@@ -175,12 +214,77 @@ const styles = StyleSheet.create({
175214

176215
</FlatList>
177216
return (
217+
178218
<View>
179-
<Button
180-
title = "Add"
181-
onPress={this._onPress}>
219+
<Modal
220+
transparent={true}
221+
visible={ this.state.isShowModal }>
222+
<View
223+
style={ styles.modalView }>
224+
<View
225+
style={ styles.modalContent}>
226+
<TextInput
227+
placeholder = "用户名或群聊名称"
228+
onChangeText = { (e) => { this.setState({modalText: e}) } }>
229+
</TextInput>
230+
<Button
231+
onPress={() => {
232+
var params = {}
233+
params.type = 'single'
234+
params.username = this.state.modalText
235+
JMessage.createConversation(params, (conv) => {
236+
var item = {}
237+
238+
if (conv.conversationType === 'single') {
239+
item = {key: conv.target.username}
240+
item.conversationType = 'single'
241+
} else {
242+
item = {key: conv.target.id}
243+
item.conversationType = 'group'
244+
Alert.alert('conversaion', JSON.stringify(conv))
245+
}
246+
this.props.navigation.navigate('Chat', {conversation: item})
247+
}, (error) => {
248+
Alert.alert('error !', JSON.stringify(error))
249+
})
250+
} }
251+
style={styles.modalButton}
252+
title='创建单聊'>
253+
</Button>
254+
<Button
255+
onPress={ () => {
182256

183-
</Button>
257+
JMessage.createGroup({name: this.state.modalText,desc: ""}, (group) => {
258+
var params = {}
259+
params.type = 'single'
260+
params.groupId = group.id
261+
JMessage.createConversation(params, (conv) => {
262+
var item = {}
263+
264+
if (conv.conversationType === 'single') {
265+
item = {key: conv.target.username}
266+
item.conversationType = 'single'
267+
} else {
268+
item = {key: conv.target.id}
269+
item.conversationType = 'group'
270+
Alert.alert('conversaion', JSON.stringify(conv))
271+
}
272+
}, (error) => {
273+
Alert.alert('error !', JSON.stringify(error))
274+
})
275+
}, (error) => {
276+
Alert.alert('error !', JSON.stringify(error))
277+
})
278+
279+
} }
280+
style={styles.modalButton}
281+
title='创建群聊'>
282+
283+
</Button>
284+
</View>
285+
286+
</View>
287+
</Modal>
184288
{ this.listView }
185289
</View>)
186290
}

example/app/routes/Home/UserInfo/index.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
Button,
1616
Alert,
1717
TextInput,
18-
Image
18+
Image,
1919
} = ReactNative;
2020

2121
const styles = StyleSheet.create({
@@ -26,6 +26,10 @@ const {
2626
borderBottomWidth: 1,
2727
borderColor: "#cccccc",
2828
},
29+
avatar: {
30+
width: 60,
31+
height: 60,
32+
},
2933
icon: {
3034
width: 26,
3135
height: 26,
@@ -75,17 +79,30 @@ export default class MyNotificationsScreen extends React.Component {
7579
JMessage.getMyInfo((user) => {
7680
// this.sta = myInfo
7781
this.setState({myInfo: user})
82+
// JMessage.downloadOriginalUserAvatar()
7883
})
84+
7985
}
8086
render() {
87+
// Alert.alert("my info ", JSON.stringify(this.state.myInfo))
88+
// Alert.alert("my info ", this.state.myInfo.avatarThumbPath)
89+
// console.log('file://' + this.state.myInfo.avatarThumbPath)
90+
if (this.state.myInfo.avatarThumbPath === "") {
91+
this.avatar = <Image
92+
source={require('../../../resource/group-icon.png')}
93+
style={styles.avatar}>
94+
</Image>
95+
} else {
96+
this.avatar = <Image
97+
source={{isStatic:true,uri:this.state.myInfo.avatarThumbPath, scale:1}}
98+
style={styles.avatar}>
99+
</Image>
100+
}
81101
return (
82102
<View>
83103
<View
84104
style={[styles.header]}>
85-
<Image
86-
source={require('../../../resource/group-icon.png')}
87-
style={[styles.header]}>
88-
</Image>
105+
{ this.avatar }
89106
<Text
90107
style={[styles.username]}>
91108
{ this.state.myInfo.nickname}

example/app/routes/Login/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ const {
1414
Button,
1515
Alert,
1616
TextInput
17-
} = ReactNative;
17+
} = ReactNative;
1818

19-
export default class Login extends React.Component {
19+
// justifyContent: 'center',
20+
// alignItems: 'center',
21+
const styles = StyleSheet.create({
22+
inputView: {
23+
margin: 10,
24+
},
25+
loginBtn: {
26+
color: "#ffffff",
27+
height: 30,
28+
backgroundColor: "#cccccc",
29+
}
30+
31+
})
32+
33+
export default class Login extends React.Component {
2034
static navigationOptions = {
2135
title: "登录"
2236
};
@@ -45,14 +59,17 @@ const {
4559
return (
4660
<View>
4761
<TextInput
62+
style={styles.inputView}
4863
placeholder = "用户名"
4964
onChangeText = { (e) => { this.setState({username: e}) } }>
5065
</TextInput>
5166
<TextInput
67+
style={styles.inputView}
5268
placeholder = "密码"
5369
onChangeText = { (e) => { this.setState({password: e}) } }>
5470
</TextInput>
5571
<FormButton
72+
style={styles.loginBtn}
5673
title="登录"
5774
onPress={this.onPress}
5875
>

example/app/views/FormButton.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ class FormButton extends Component {
3535
constructor(props) {
3636
super(props);
3737
this.title = props.title
38+
this.style = props.style
3839
this.onPress = this.onPress.bind(this);
3940
}
4041

4142
onPress() {
4243
if (!this.props.onPress) {
4344
return;
4445
}
45-
this.props.onPress();
46+
this.props.onPress();
4647
}
4748

4849
render () {
4950
return (
5051
<Button
52+
style={this.style}
5153
color="#FF3366"
5254
title={this.title}
5355
onPress = {this.onPress}

example/index.ios.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@ const ReactJChat = StackNavigator({
3333
},
3434
},
3535
Login: {
36-
screen: LoginPage
36+
screen: LoginPage,
37+
navigationOptions: {
38+
headerLeft: null,
39+
gesturesEnabled: false,
40+
},
3741
},
3842
Chat: {
3943
type: 'Reset',
4044
screen: ChatPage,
4145
path: 'people/:conversation'
4246
}
43-
},{
44-
// mode:'modal',
45-
headerMode: 'screen',
46-
transitionConfig:() => ({
47-
screenInterpolator:CardStackStyleInterpolator.forInitial,
48-
})
4947
});
5048

49+
// ,{
50+
// headerMode: 'screen',
51+
// transitionConfig:() => ({
52+
// screenInterpolator:CardStackStyleInterpolator.forInitial,
53+
// })
54+
// }
55+
5156
AppRegistry.registerComponent('ReactJChat', () => ReactJChat);

0 commit comments

Comments
 (0)