@@ -39,7 +39,6 @@ import {
39
39
} from './Constant' ;
40
40
41
41
class GiftedChat extends React . Component {
42
-
43
42
constructor ( props ) {
44
43
super ( props ) ;
45
44
@@ -54,15 +53,10 @@ class GiftedChat extends React.Component {
54
53
55
54
this . state = {
56
55
isInitialized : false , // initialization will calculate maxHeight before rendering the chat
57
- composerHeight : this . props . minComposerHeight ,
58
- messagesContainerHeight : null ,
56
+ composerHeight : 40 ,
59
57
typingDisabled : false ,
60
58
} ;
61
59
62
- this . onKeyboardWillShow = this . onKeyboardWillShow . bind ( this ) ;
63
- this . onKeyboardWillHide = this . onKeyboardWillHide . bind ( this ) ;
64
- this . onKeyboardDidShow = this . onKeyboardDidShow . bind ( this ) ;
65
- this . onKeyboardDidHide = this . onKeyboardDidHide . bind ( this ) ;
66
60
this . onSend = this . onSend . bind ( this ) ;
67
61
this . getLocale = this . getLocale . bind ( this ) ;
68
62
this . onInputSizeChanged = this . onInputSizeChanged . bind ( this ) ;
@@ -72,11 +66,6 @@ class GiftedChat extends React.Component {
72
66
73
67
this . invertibleScrollViewProps = {
74
68
inverted : this . props . inverted ,
75
- keyboardShouldPersistTaps : this . props . keyboardShouldPersistTaps ,
76
- onKeyboardWillShow : this . onKeyboardWillShow ,
77
- onKeyboardWillHide : this . onKeyboardWillHide ,
78
- onKeyboardDidShow : this . onKeyboardDidShow ,
79
- onKeyboardDidHide : this . onKeyboardDidHide ,
80
69
} ;
81
70
}
82
71
@@ -156,23 +145,6 @@ class GiftedChat extends React.Component {
156
145
return this . _messages ;
157
146
}
158
147
159
- setMaxHeight ( height ) {
160
- this . _maxHeight = height ;
161
- }
162
-
163
- getMaxHeight ( ) {
164
- return this . _maxHeight ;
165
- }
166
-
167
- setKeyboardHeight ( height ) {
168
- this . _keyboardHeight = 0 ;
169
- }
170
-
171
- getKeyboardHeight ( ) {
172
- return 0 ;
173
- }
174
-
175
-
176
148
setBottomOffset ( value ) {
177
149
this . _bottomOffset = value ;
178
150
}
@@ -207,82 +179,9 @@ class GiftedChat extends React.Component {
207
179
return this . _isMounted ;
208
180
}
209
181
210
- // TODO: setMinInputToolbarHeight
211
- getMinInputToolbarHeight ( ) {
212
- return this . props . renderAccessory
213
- ? this . props . minInputToolbarHeight * 2
214
- : this . props . minInputToolbarHeight ;
215
- }
216
- calculateInputToolbarHeight ( composerHeight ) {
217
- return composerHeight + ( this . getMinInputToolbarHeight ( ) - this . props . minComposerHeight ) ;
218
- }
219
-
220
- /**
221
- * Returns the height, based on current window size, without taking the keyboard into account.
222
- */
223
- getBasicMessagesContainerHeight ( composerHeight = this . state . composerHeight ) {
224
- return this . getMaxHeight ( ) - this . calculateInputToolbarHeight ( composerHeight ) ;
225
- }
226
-
227
- /**
228
- * Returns the height, based on current window size, taking the keyboard into account.
229
- */
230
- getMessagesContainerHeightWithKeyboard ( composerHeight = this . state . composerHeight ) {
231
- return this . getBasicMessagesContainerHeight ( composerHeight ) - this . getKeyboardHeight ( ) + this . getBottomOffset ( ) ;
232
- }
233
-
234
- prepareMessagesContainerHeight ( value ) {
235
- if ( this . props . isAnimated === true ) {
236
- return new Animated . Value ( value ) ;
237
- }
238
- return value ;
239
- }
240
-
241
- onKeyboardWillShow ( e ) {
242
- this . setIsTypingDisabled ( true ) ;
243
- this . setKeyboardHeight ( e . endCoordinates ? e . endCoordinates . height : e . end . height ) ;
244
- this . setBottomOffset ( this . props . bottomOffset ) ;
245
- const newMessagesContainerHeight = this . getMessagesContainerHeightWithKeyboard ( ) ;
246
- if ( this . props . isAnimated === true ) {
247
- Animated . timing ( this . state . messagesContainerHeight , {
248
- toValue : newMessagesContainerHeight ,
249
- duration : 210 ,
250
- } ) . start ( ) ;
251
- } else {
252
- this . setState ( {
253
- messagesContainerHeight : newMessagesContainerHeight ,
254
- } ) ;
255
- }
256
- }
257
-
258
- onKeyboardWillHide ( ) {
259
- this . setIsTypingDisabled ( true ) ;
260
- this . setKeyboardHeight ( 0 ) ;
261
- this . setBottomOffset ( 0 ) ;
262
- const newMessagesContainerHeight = this . getBasicMessagesContainerHeight ( ) ;
263
- if ( this . props . isAnimated === true ) {
264
- Animated . timing ( this . state . messagesContainerHeight , {
265
- toValue : newMessagesContainerHeight ,
266
- duration : 210 ,
267
- } ) . start ( ) ;
268
- } else {
269
- this . setState ( {
270
- messagesContainerHeight : newMessagesContainerHeight ,
271
- } ) ;
272
- }
273
- }
274
-
275
- onKeyboardDidShow ( e ) {
276
- this . setIsTypingDisabled ( false ) ;
277
- }
278
-
279
- onKeyboardDidHide ( e ) {
280
- this . setIsTypingDisabled ( false ) ;
281
- }
282
-
283
182
scrollToBottom ( animated = true ) {
284
183
if ( this . _messageContainerRef === null ) {
285
- return
184
+ return ;
286
185
}
287
186
this . _messageContainerRef . scrollTo ( {
288
187
y : 0 ,
@@ -294,9 +193,10 @@ class GiftedChat extends React.Component {
294
193
renderMessages ( ) {
295
194
return (
296
195
< div style = { {
297
- height : this . state . messagesContainerHeight ,
298
- display : 'flex'
299
- } } >
196
+ height : `calc(100% - ${ this . state . composerHeight } px)` ,
197
+ display : 'flex' ,
198
+ } }
199
+ >
300
200
< MessageContainer
301
201
{ ...this . props }
302
202
invertibleScrollViewProps = { this . invertibleScrollViewProps }
@@ -312,14 +212,12 @@ class GiftedChat extends React.Component {
312
212
if ( ! Array . isArray ( messages ) ) {
313
213
messages = [ messages ] ;
314
214
}
315
- messages = messages . map ( ( message ) => {
316
- return {
317
- ...message ,
318
- user : this . props . user ,
319
- createdAt : new Date ( ) ,
320
- id : this . props . messageIdGenerator ( ) ,
321
- } ;
322
- } ) ;
215
+ messages = messages . map ( message => ( {
216
+ ...message ,
217
+ user : this . props . user ,
218
+ createdAt : new Date ( ) ,
219
+ id : this . props . messageIdGenerator ( ) ,
220
+ } ) ) ;
323
221
324
222
if ( shouldResetInputToolbar === true ) {
325
223
this . setIsTypingDisabled ( true ) ;
@@ -343,12 +241,8 @@ class GiftedChat extends React.Component {
343
241
this . textInput . clear ( ) ;
344
242
}
345
243
this . notifyInputTextReset ( ) ;
346
- const newComposerHeight = this . props . minComposerHeight ;
347
- const newMessagesContainerHeight = this . getMessagesContainerHeightWithKeyboard ( newComposerHeight ) ;
348
244
this . setState ( {
349
245
text : this . getTextFromProp ( '' ) ,
350
- composerHeight : newComposerHeight ,
351
- messagesContainerHeight : this . prepareMessagesContainerHeight ( newMessagesContainerHeight ) ,
352
246
} ) ;
353
247
}
354
248
@@ -359,17 +253,6 @@ class GiftedChat extends React.Component {
359
253
}
360
254
361
255
onInputSizeChanged ( size ) {
362
- const newComposerHeight = Math . max (
363
- this . props . minComposerHeight ,
364
- Math . min ( this . props . maxComposerHeight , size . height ) ,
365
- ) ;
366
- const newMessagesContainerHeight = this . getMessagesContainerHeightWithKeyboard (
367
- newComposerHeight ,
368
- ) ;
369
- this . setState ( {
370
- composerHeight : newComposerHeight ,
371
- messagesContainerHeight : this . prepareMessagesContainerHeight ( newMessagesContainerHeight ) ,
372
- } ) ;
373
256
}
374
257
375
258
onInputTextChanged ( text ) {
@@ -397,14 +280,9 @@ class GiftedChat extends React.Component {
397
280
return ;
398
281
}
399
282
this . notifyInputTextReset ( ) ;
400
- this . setMaxHeight ( 1000 ) ;
401
- const newComposerHeight = '100%' ;
402
- const newMessagesContainerHeight = newComposerHeight ; // this.getMessagesContainerHeightWithKeyboard(newComposerHeight);
403
283
this . setState ( {
404
284
isInitialized : true ,
405
285
text : this . getTextFromProp ( '' ) ,
406
- composerHeight : newComposerHeight ,
407
- messagesContainerHeight : this . prepareMessagesContainerHeight ( newMessagesContainerHeight ) ,
408
286
} ) ;
409
287
}
410
288
@@ -415,13 +293,13 @@ class GiftedChat extends React.Component {
415
293
const inputToolbarProps = {
416
294
...this . props ,
417
295
text : this . getTextFromProp ( this . state . text ) ,
418
- composerHeight : Math . max ( this . props . minComposerHeight , this . state . composerHeight ) ,
296
+ composerHeight : this . state . composerHeight ,
419
297
onSend : this . onSend ,
420
298
onInputSizeChanged : this . onInputSizeChanged ,
421
299
onTextChanged : this . onInputTextChanged ,
422
300
textInputProps : {
423
301
...this . props . textInputProps ,
424
- ref : ( textInput ) => ( this . textInput = textInput ) ,
302
+ ref : textInput => ( this . textInput = textInput ) ,
425
303
maxLength : this . getIsTypingDisabled ( ) ? 0 : this . props . maxInputLength ,
426
304
} ,
427
305
} ;
@@ -467,13 +345,12 @@ class GiftedChat extends React.Component {
467
345
</ View >
468
346
) ;
469
347
}
470
-
471
348
}
472
349
473
350
const styles = StyleSheet . create ( {
474
351
container : {
475
352
flex : 1 ,
476
- height : '100%'
353
+ height : '100%' ,
477
354
} ,
478
355
} ) ;
479
356
0 commit comments