@@ -78,29 +78,34 @@ const styles = StyleSheet.create({
7878
7979 var count = 0
8080
81- export default class ConversationList extends React . Component {
82- static navigationOptions = {
83- headerRight : < Button
84- title = "创建会话"
85- onPress = {
86- ( { state} ) => {
87- Alert . alert ( 'state' , JSON . stringify ( state . params ) )
81+ // headerRight: <Button
82+ // title="创建会话"
83+ // onPress={
84+ // ({state}) => {
85+ // Alert.alert('state', JSON.stringify(state.params))
8886
89- } }
90- /> ,
91- title : "会话" ,
92- tabBarLabel : '会话' ,
93- tabBarIcon : ( { tintColor } ) => (
94- < Image
95- source = { require ( '../../../resource/chat-icon.png' ) }
96- style = { [ styles . icon , { tintColor : tintColor } ] }
97- />
98- ) ,
99- } ;
87+ // }}
88+ // />,
10089
101- onCreateConversation ( ) {
102- // this.setState({isShowModal: true})
103- Alert . alert ( "click" , "success" )
90+ export default class ConversationList extends React . Component {
91+ static navigationOptions = ( { navigation} ) => {
92+ const { params = { } } = navigation . state ;
93+ return {
94+ headerRight :
95+ < Button title = "创建会话" onPress = { ( ) => { params . createConversation ( ) } } /> ,
96+ title : "会话" ,
97+ tabBarLabel : '会话' ,
98+ tabBarIcon : ( { tintColor } ) => (
99+ < Image
100+ source = { require ( '../../../resource/chat-icon.png' ) }
101+ style = { [ styles . icon , { tintColor : tintColor } ] }
102+ />
103+ ) ,
104+ }
105+ } ;
106+
107+ _onCreateConversation ( ) {
108+ this . setState ( { isShowModal : true } )
104109 }
105110
106111 constructor ( props ) {
@@ -110,13 +115,11 @@ const styles = StyleSheet.create({
110115 modalText : "" ,
111116 isShowModal : false ,
112117 }
113- // this.onCreateConversation = this.onCreateConversation.bind(this)
114- // this.props.navigation.setParams({ createConversastion: this.onCreateConversation });
118+ this . _onCreateConversation = this . _onCreateConversation . bind ( this )
115119 }
116120
117121 componentDidMount ( ) {
118- this . props . navigation . setParams ( { createConversastion : this . onCreateConversation } ) ;
119- this . props . navigation . setParams ( { test : 'test' } ) ;
122+ this . props . navigation . setParams ( { createConversation : this . _onCreateConversation } ) ;
120123 }
121124 componentWillMount ( ) {
122125 JMessage . getConversations ( ( result ) => {
@@ -178,6 +181,7 @@ const styles = StyleSheet.create({
178181 item . conversationType = 'group'
179182 Alert . alert ( 'conversaion' , JSON . stringify ( conv ) )
180183 }
184+ this . setState ( { } )
181185 this . props . navigation . navigate ( 'Chat' , { conversation : item } )
182186 } , ( error ) => {
183187 Alert . alert ( 'error' , JSON . stringify ( error ) )
@@ -232,6 +236,7 @@ const styles = StyleSheet.create({
232236 var params = { }
233237 params . type = 'single'
234238 params . username = this . state . modalText
239+ this . setState ( { isShowModal : false } )
235240 JMessage . createConversation ( params , ( conv ) => {
236241 var item = { }
237242
@@ -243,6 +248,7 @@ const styles = StyleSheet.create({
243248 item . conversationType = 'group'
244249 Alert . alert ( 'conversaion' , JSON . stringify ( conv ) )
245250 }
251+
246252 this . props . navigation . navigate ( 'Chat' , { conversation : item } )
247253 } , ( error ) => {
248254 Alert . alert ( 'error !' , JSON . stringify ( error ) )
@@ -258,6 +264,7 @@ const styles = StyleSheet.create({
258264 var params = { }
259265 params . type = 'single'
260266 params . groupId = group . id
267+ this . setState ( { isShowModal : false } )
261268 JMessage . createConversation ( params , ( conv ) => {
262269 var item = { }
263270
@@ -269,6 +276,7 @@ const styles = StyleSheet.create({
269276 item . conversationType = 'group'
270277 Alert . alert ( 'conversaion' , JSON . stringify ( conv ) )
271278 }
279+ this . props . navigation . navigate ( 'Chat' , { conversation : item } )
272280 } , ( error ) => {
273281 Alert . alert ( 'error !' , JSON . stringify ( error ) )
274282 } )
0 commit comments