@@ -23,20 +23,23 @@ const supportedKeyboardEvents = [
23
23
'keyboardWillHide' ,
24
24
'keyboardDidHide' ,
25
25
'keyboardWillChangeFrame' ,
26
- 'keyboardDidChangeFrame' ,
26
+ 'keyboardDidChangeFrame'
27
27
]
28
- const keyboardEventToCallbackName = ( eventName : string ) => (
28
+ const keyboardEventToCallbackName = ( eventName : string ) =>
29
29
'on' + eventName [ 0 ] . toUpperCase ( ) + eventName . substring ( 1 )
30
- )
31
30
const keyboardEventPropTypes = supportedKeyboardEvents . reduce (
32
- ( acc : Object , eventName : string ) => (
33
- { ...acc , [ keyboardEventToCallbackName ( eventName ) ] : PropTypes . func }
34
- ) , { }
31
+ ( acc : Object , eventName : string ) => ( {
32
+ ...acc ,
33
+ [ keyboardEventToCallbackName ( eventName ) ] : PropTypes . func
34
+ } ) ,
35
+ { }
35
36
)
36
37
const keyboardAwareHOCTypeEvents = supportedKeyboardEvents . reduce (
37
- ( acc : Object , eventName : string ) => (
38
- { ...acc , [ keyboardEventToCallbackName ( eventName ) ] : Function }
39
- ) , { }
38
+ ( acc : Object , eventName : string ) => ( {
39
+ ...acc ,
40
+ [ keyboardEventToCallbackName ( eventName ) ] : Function
41
+ } ) ,
42
+ { }
40
43
)
41
44
42
45
export type KeyboardAwareHOCProps = {
@@ -87,10 +90,6 @@ export type ScrollIntoViewOptions = ?{
87
90
) => ScrollPosition
88
91
}
89
92
90
-
91
-
92
-
93
-
94
93
export type KeyboardAwareHOCOptions = ?{
95
94
enableOnAndroid : boolean ,
96
95
contentContainerStyle : ?Object ,
@@ -128,26 +127,26 @@ const ScrollIntoViewDefaultOptions: KeyboardAwareHOCOptions = {
128
127
// getNode() permit to support Animated.ScrollView automatically
129
128
// see https://github.com/facebook/react-native/issues/19650
130
129
// see https://stackoverflow.com/questions/42051368/scrollto-is-undefined-on-animated-scrollview/48786374
131
- if ( ref . getNode ) {
130
+ if ( ref . getNode ) {
132
131
return ref . getNode ( )
133
- }
134
- else {
132
+ } else {
135
133
return ref
136
134
}
137
- } ,
135
+ }
138
136
}
139
137
140
- function KeyboardAwareHOC ( ScrollableComponent : React$Component , userOptions : KeyboardAwareHOCOptions ) {
141
-
138
+ function KeyboardAwareHOC (
139
+ ScrollableComponent : React$Component ,
140
+ userOptions : KeyboardAwareHOCOptions
141
+ ) {
142
142
const hocOptions : KeyboardAwareHOCOptions = {
143
143
...ScrollIntoViewDefaultOptions ,
144
- ...userOptions ,
144
+ ...userOptions
145
145
}
146
146
147
- return class extends React . Component <
148
- KeyboardAwareHOCProps ,
149
- KeyboardAwareHOCState
150
- > implements KeyboardAwareInterface {
147
+ return class
148
+ extends React . Component < KeyboardAwareHOCProps , KeyboardAwareHOCState >
149
+ implements KeyboardAwareInterface {
151
150
_rnkasv_keyboardView : any
152
151
keyboardWillShowEvent : ?Function
153
152
keyboardWillHideEvent : ?Function
@@ -172,7 +171,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
172
171
keyboardOpeningTime : PropTypes . number ,
173
172
onScroll : PropTypes . oneOfType ( [
174
173
PropTypes . func , // Normal listener
175
- PropTypes . object , // Animated.event listener
174
+ PropTypes . object // Animated.event listener
176
175
] ) ,
177
176
update : PropTypes . func ,
178
177
contentContainerStyle : PropTypes . any ,
@@ -189,7 +188,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
189
188
enableResetScrollToCoords : hocOptions . enableResetScrollToCoords ,
190
189
keyboardOpeningTime : hocOptions . keyboardOpeningTime ,
191
190
viewIsInsideTabBar : hocOptions . viewIsInsideTabBar ,
192
- enableOnAndroid : hocOptions . enableOnAndroid ,
191
+ enableOnAndroid : hocOptions . enableOnAndroid
193
192
}
194
193
195
194
constructor ( props : KeyboardAwareHOCProps ) {
@@ -231,7 +230,10 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
231
230
supportedKeyboardEvents . forEach ( ( eventName : string ) => {
232
231
const callbackName = keyboardEventToCallbackName ( eventName )
233
232
if ( this . props [ callbackName ] ) {
234
- this . callbacks [ eventName ] = Keyboard . addListener ( eventName , this . props [ callbackName ] )
233
+ this . callbacks [ eventName ] = Keyboard . addListener (
234
+ eventName ,
235
+ this . props [ callbackName ]
236
+ )
235
237
}
236
238
} )
237
239
}
@@ -251,7 +253,9 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
251
253
this . mountedComponent = false
252
254
this . keyboardWillShowEvent && this . keyboardWillShowEvent . remove ( )
253
255
this . keyboardWillHideEvent && this . keyboardWillHideEvent . remove ( )
254
- Object . values ( this . callbacks ) . forEach ( ( callback : Object ) => callback . remove ( ) )
256
+ Object . values ( this . callbacks ) . forEach ( ( callback : Object ) =>
257
+ callback . remove ( )
258
+ )
255
259
}
256
260
257
261
getScrollResponder = ( ) => {
@@ -296,11 +300,11 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
296
300
}
297
301
const responder = this . getScrollResponder ( )
298
302
responder &&
299
- responder . scrollResponderScrollNativeHandleToKeyboard (
300
- reactNode ,
301
- extraHeight ,
302
- true
303
- )
303
+ responder . scrollResponderScrollNativeHandleToKeyboard (
304
+ reactNode ,
305
+ extraHeight ,
306
+ true
307
+ )
304
308
} , keyboardOpeningTime )
305
309
}
306
310
@@ -312,16 +316,18 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
312
316
return
313
317
}
314
318
315
- const [
316
- parentLayout ,
317
- childLayout
318
- ] = await Promise . all ( [
319
+ const [ parentLayout , childLayout ] = await Promise . all ( [
319
320
this . _measureElement ( this . _rnkasv_keyboardView ) ,
320
321
this . _measureElement ( element )
321
322
] )
322
323
323
- const getScrollPosition = options . getScrollPosition || this . _defaultGetScrollPosition
324
- const { x, y, animated } = getScrollPosition ( parentLayout , childLayout , this . position )
324
+ const getScrollPosition =
325
+ options . getScrollPosition || this . _defaultGetScrollPosition
326
+ const { x, y, animated } = getScrollPosition (
327
+ parentLayout ,
328
+ childLayout ,
329
+ this . position
330
+ )
325
331
this . scrollToPosition ( x , y , animated )
326
332
}
327
333
@@ -333,24 +339,28 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
333
339
return {
334
340
x : 0 ,
335
341
y : Math . max ( 0 , childLayout . y - parentLayout . y + contentOffset . y ) ,
336
- animated : true ,
342
+ animated : true
337
343
}
338
344
}
339
345
340
346
_measureElement = ( element : React . Element < * > ) : Promise < ElementLayout > => {
341
347
const node = findNodeHandle ( element )
342
- return new Promise ( ( resolve : ( ElementLayout ) = > void ) => {
343
- UIManager . measureInWindow ( node , ( x : number , y : number , width : number , height : number ) => {
344
- resolve ( { x, y, width, height } )
345
- } )
348
+ return new Promise ( ( resolve : ElementLayout => void ) => {
349
+ UIManager . measureInWindow (
350
+ node ,
351
+ ( x : number , y : number , width : number , height : number ) => {
352
+ resolve ( { x, y, width, height } )
353
+ }
354
+ )
346
355
} )
347
356
}
348
357
349
358
// Keyboard actions
350
359
_updateKeyboardSpace = ( frames : Object ) => {
351
360
// Automatically scroll to focused TextInput
352
361
if ( this . props . enableAutomaticScroll ) {
353
- let keyboardSpace : number = frames . endCoordinates . height + this . props . extraScrollHeight
362
+ let keyboardSpace : number =
363
+ frames . endCoordinates . height + this . props . extraScrollHeight
354
364
if ( this . props . viewIsInsideTabBar ) {
355
365
keyboardSpace -= _KAM_DEFAULT_TAB_BAR_HEIGHT
356
366
}
@@ -400,7 +410,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
400
410
) {
401
411
this . scrollForExtraHeightOnAndroid (
402
412
totalExtraHeight -
403
- ( keyboardPosition - textInputBottomPosition )
413
+ ( keyboardPosition - textInputBottomPosition )
404
414
)
405
415
}
406
416
}
@@ -481,9 +491,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
481
491
return
482
492
}
483
493
484
- this . _scrollToFocusedInputWithNodeHandle (
485
- currentlyFocusedField
486
- )
494
+ this . _scrollToFocusedInputWithNodeHandle ( currentlyFocusedField )
487
495
}
488
496
489
497
render ( ) {
@@ -492,8 +500,8 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
492
500
if ( Platform . OS === 'android' && enableOnAndroid ) {
493
501
newContentContainerStyle = [ ] . concat ( contentContainerStyle ) . concat ( {
494
502
paddingBottom :
495
- ( ( contentContainerStyle || { } ) . paddingBottom || 0 ) +
496
- this . state . keyboardSpace
503
+ ( ( contentContainerStyle || { } ) . paddingBottom || 0 ) +
504
+ this . state . keyboardSpace
497
505
} )
498
506
}
499
507
const refProps = { [ hocOptions . refPropName ] : this . _handleRef }
@@ -519,7 +527,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
519
527
resetKeyboardSpace = { this . _resetKeyboardSpace }
520
528
handleOnScroll = { this . _handleOnScroll }
521
529
update = { this . update }
522
- onScroll = { Animated . forkEvent ( onScroll , this . _handleOnScroll ) }
530
+ onScroll = { Animated . forkEvent ( onScroll , this . _handleOnScroll ) }
523
531
/>
524
532
)
525
533
}
@@ -530,10 +538,9 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
530
538
// listenToKeyboardEvents(ScrollView);
531
539
// listenToKeyboardEvents(options)(Comp);
532
540
const listenToKeyboardEvents = ( configOrComp : any ) = > {
533
- if ( typeof configOrComp === 'object' ) {
534
- return ( Comp : Function ) => KeyboardAwareHOC ( Comp , configOrComp )
535
- }
536
- else {
541
+ if ( typeof configOrComp === 'object' ) {
542
+ return ( Comp : Function ) => KeyboardAwareHOC ( Comp , configOrComp )
543
+ } else {
537
544
return KeyboardAwareHOC ( configOrComp )
538
545
}
539
546
}
0 commit comments