@@ -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 }
0 commit comments