@@ -74,10 +74,9 @@ export const updateTextInput = (textInput: TextInput, text: string): void => {
74
74
return ;
75
75
}
76
76
77
- if ( text ) {
78
- textInput . setNativeProps ( { text } ) ;
79
- } else {
80
- textInput . clear ( ) ;
77
+ textInput . setNativeProps ( { text } ) ;
78
+
79
+ if ( text . length === 0 ) {
81
80
if ( TextInputReset ) {
82
81
TextInputReset . resetKeyboardInput ( findNodeHandle ( textInput ) ) ;
83
82
}
@@ -106,6 +105,16 @@ class ComposeBox extends PureComponent<Props, State> {
106
105
selection : { start : 0 , end : 0 } ,
107
106
} ;
108
107
108
+ setMessageInputValue = ( message : string ) => {
109
+ updateTextInput ( this . messageInput , message ) ;
110
+ this . handleMessageChange ( message ) ;
111
+ } ;
112
+
113
+ setTopicInputValue = ( topic : string ) => {
114
+ updateTextInput ( this . topicInput , topic ) ;
115
+ this . handleTopicChange ( topic ) ;
116
+ } ;
117
+
109
118
handleComposeMenuToggle = ( ) => {
110
119
this . setState ( ( { isMenuExpanded } ) => ( {
111
120
isMenuExpanded : ! isMenuExpanded ,
@@ -122,9 +131,8 @@ class ComposeBox extends PureComponent<Props, State> {
122
131
this . setState ( { topic, isMenuExpanded : false } ) ;
123
132
} ;
124
133
125
- handleTopicAutocomplete = ( message : string ) => {
126
- this . handleTopicChange ( message ) ;
127
- updateTextInput ( this . topicInput , message ) ;
134
+ handleTopicAutocomplete = ( topic : string ) => {
135
+ this . setTopicInputValue ( topic ) ;
128
136
} ;
129
137
130
138
handleMessageChange = ( message : string ) => {
@@ -134,8 +142,7 @@ class ComposeBox extends PureComponent<Props, State> {
134
142
} ;
135
143
136
144
handleMessageAutocomplete = ( message : string ) => {
137
- this . handleMessageChange ( message ) ;
138
- updateTextInput ( this . messageInput , message ) ;
145
+ this . setMessageInputValue ( message ) ;
139
146
} ;
140
147
141
148
handleMessageSelectionChange = ( event : Object ) => {
@@ -144,12 +151,15 @@ class ComposeBox extends PureComponent<Props, State> {
144
151
} ;
145
152
146
153
handleMessageFocus = ( ) => {
154
+ const { topic } = this . state ;
147
155
const { lastMessageTopic } = this . props ;
148
- this . setState ( ( { topic } ) => ( {
156
+ this . setState ( {
149
157
isMessageFocused : true ,
150
158
isMenuExpanded : false ,
151
- topic : topic || lastMessageTopic ,
152
- } ) ) ;
159
+ } ) ;
160
+ setTimeout ( ( ) => {
161
+ this . setTopicInputValue ( topic || lastMessageTopic ) ;
162
+ } , 200 ) ;
153
163
} ;
154
164
155
165
handleMessageBlur = ( ) => {
@@ -193,6 +203,7 @@ class ComposeBox extends PureComponent<Props, State> {
193
203
194
204
dispatch ( addToOutbox ( destinationNarrow , message ) ) ;
195
205
dispatch ( draftRemove ( narrow ) ) ;
206
+ this . setMessageInputValue ( '' ) ;
196
207
} ;
197
208
198
209
handleEdit = ( ) => {
@@ -227,22 +238,28 @@ class ComposeBox extends PureComponent<Props, State> {
227
238
this . tryUpdateDraft ( ) ;
228
239
}
229
240
241
+ componentDidMount ( ) {
242
+ const { message, topic } = this . state ;
243
+
244
+ updateTextInput ( this . messageInput , message ) ;
245
+ updateTextInput ( this . topicInput , topic ) ;
246
+ }
247
+
230
248
componentWillReceiveProps ( nextProps : Props ) {
231
249
if ( nextProps . editMessage !== this . props . editMessage ) {
232
250
const topic =
233
251
isStreamNarrow ( nextProps . narrow ) && nextProps . editMessage
234
252
? nextProps . editMessage . topic
235
253
: '' ;
236
- this . setState ( {
237
- message : nextProps . editMessage ? nextProps . editMessage . content : '' ,
238
- topic,
239
- } ) ;
254
+ const message = nextProps . editMessage ? nextProps . editMessage . content : '' ;
255
+ this . setMessageInputValue ( message ) ;
256
+ this . setTopicInputValue ( topic ) ;
240
257
if ( this . messageInput ) {
241
258
this . messageInput . focus ( ) ;
242
259
}
243
260
} else if ( ! isEqual ( nextProps . narrow , this . props . narrow ) ) {
244
261
this . tryUpdateDraft ( ) ;
245
- this . setState ( { message : nextProps . draft } ) ;
262
+ this . setMessageInputValue ( nextProps . draft ) ;
246
263
}
247
264
}
248
265
0 commit comments