@@ -23,20 +23,23 @@ const supportedKeyboardEvents = [
2323 'keyboardWillHide' ,
2424 'keyboardDidHide' ,
2525 'keyboardWillChangeFrame' ,
26- 'keyboardDidChangeFrame' ,
26+ 'keyboardDidChangeFrame'
2727]
28- const keyboardEventToCallbackName = ( eventName : string ) => (
28+ const keyboardEventToCallbackName = ( eventName : string ) =>
2929 'on' + eventName [ 0 ] . toUpperCase ( ) + eventName . substring ( 1 )
30- )
3130const 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+ { }
3536)
3637const 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+ { }
4043)
4144
4245export type KeyboardAwareHOCProps = {
@@ -87,10 +90,6 @@ export type ScrollIntoViewOptions = ?{
8790 ) => ScrollPosition
8891}
8992
90-
91-
92-
93-
9493export type KeyboardAwareHOCOptions = ?{
9594 enableOnAndroid : boolean ,
9695 contentContainerStyle : ?Object ,
@@ -128,26 +127,26 @@ const ScrollIntoViewDefaultOptions: KeyboardAwareHOCOptions = {
128127 // getNode() permit to support Animated.ScrollView automatically
129128 // see https://github.com/facebook/react-native/issues/19650
130129 // see https://stackoverflow.com/questions/42051368/scrollto-is-undefined-on-animated-scrollview/48786374
131- if ( ref . getNode ) {
130+ if ( ref . getNode ) {
132131 return ref . getNode ( )
133- }
134- else {
132+ } else {
135133 return ref
136134 }
137- } ,
135+ }
138136}
139137
140- function KeyboardAwareHOC ( ScrollableComponent : React$Component , userOptions : KeyboardAwareHOCOptions ) {
141-
138+ function KeyboardAwareHOC (
139+ ScrollableComponent : React$Component ,
140+ userOptions : KeyboardAwareHOCOptions
141+ ) {
142142 const hocOptions : KeyboardAwareHOCOptions = {
143143 ...ScrollIntoViewDefaultOptions ,
144- ...userOptions ,
144+ ...userOptions
145145 }
146146
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 {
151150 _rnkasv_keyboardView : any
152151 keyboardWillShowEvent : ?Function
153152 keyboardWillHideEvent : ?Function
@@ -172,7 +171,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
172171 keyboardOpeningTime : PropTypes . number ,
173172 onScroll : PropTypes . oneOfType ( [
174173 PropTypes . func , // Normal listener
175- PropTypes . object , // Animated.event listener
174+ PropTypes . object // Animated.event listener
176175 ] ) ,
177176 update : PropTypes . func ,
178177 contentContainerStyle : PropTypes . any ,
@@ -189,7 +188,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
189188 enableResetScrollToCoords : hocOptions . enableResetScrollToCoords ,
190189 keyboardOpeningTime : hocOptions . keyboardOpeningTime ,
191190 viewIsInsideTabBar : hocOptions . viewIsInsideTabBar ,
192- enableOnAndroid : hocOptions . enableOnAndroid ,
191+ enableOnAndroid : hocOptions . enableOnAndroid
193192 }
194193
195194 constructor ( props : KeyboardAwareHOCProps ) {
@@ -231,7 +230,10 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
231230 supportedKeyboardEvents . forEach ( ( eventName : string ) => {
232231 const callbackName = keyboardEventToCallbackName ( eventName )
233232 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+ )
235237 }
236238 } )
237239 }
@@ -251,7 +253,9 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
251253 this . mountedComponent = false
252254 this . keyboardWillShowEvent && this . keyboardWillShowEvent . remove ( )
253255 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+ )
255259 }
256260
257261 getScrollResponder = ( ) => {
@@ -296,11 +300,11 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
296300 }
297301 const responder = this . getScrollResponder ( )
298302 responder &&
299- responder . scrollResponderScrollNativeHandleToKeyboard (
300- reactNode ,
301- extraHeight ,
302- true
303- )
303+ responder . scrollResponderScrollNativeHandleToKeyboard (
304+ reactNode ,
305+ extraHeight ,
306+ true
307+ )
304308 } , keyboardOpeningTime )
305309 }
306310
@@ -312,16 +316,18 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
312316 return
313317 }
314318
315- const [
316- parentLayout ,
317- childLayout
318- ] = await Promise . all ( [
319+ const [ parentLayout , childLayout ] = await Promise . all ( [
319320 this . _measureElement ( this . _rnkasv_keyboardView ) ,
320321 this . _measureElement ( element )
321322 ] )
322323
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+ )
325331 this . scrollToPosition ( x , y , animated )
326332 }
327333
@@ -333,24 +339,28 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
333339 return {
334340 x : 0 ,
335341 y : Math . max ( 0 , childLayout . y - parentLayout . y + contentOffset . y ) ,
336- animated : true ,
342+ animated : true
337343 }
338344 }
339345
340346 _measureElement = ( element : React . Element < * > ) : Promise < ElementLayout > => {
341347 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+ )
346355 } )
347356 }
348357
349358 // Keyboard actions
350359 _updateKeyboardSpace = ( frames : Object ) => {
351360 // Automatically scroll to focused TextInput
352361 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
354364 if ( this . props . viewIsInsideTabBar ) {
355365 keyboardSpace -= _KAM_DEFAULT_TAB_BAR_HEIGHT
356366 }
@@ -400,7 +410,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
400410 ) {
401411 this . scrollForExtraHeightOnAndroid (
402412 totalExtraHeight -
403- ( keyboardPosition - textInputBottomPosition )
413+ ( keyboardPosition - textInputBottomPosition )
404414 )
405415 }
406416 }
@@ -481,9 +491,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
481491 return
482492 }
483493
484- this . _scrollToFocusedInputWithNodeHandle (
485- currentlyFocusedField
486- )
494+ this . _scrollToFocusedInputWithNodeHandle ( currentlyFocusedField )
487495 }
488496
489497 render ( ) {
@@ -492,8 +500,8 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
492500 if ( Platform . OS === 'android' && enableOnAndroid ) {
493501 newContentContainerStyle = [ ] . concat ( contentContainerStyle ) . concat ( {
494502 paddingBottom :
495- ( ( contentContainerStyle || { } ) . paddingBottom || 0 ) +
496- this . state . keyboardSpace
503+ ( ( contentContainerStyle || { } ) . paddingBottom || 0 ) +
504+ this . state . keyboardSpace
497505 } )
498506 }
499507 const refProps = { [ hocOptions . refPropName ] : this . _handleRef }
@@ -519,7 +527,7 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
519527 resetKeyboardSpace = { this . _resetKeyboardSpace }
520528 handleOnScroll = { this . _handleOnScroll }
521529 update = { this . update }
522- onScroll = { Animated . forkEvent ( onScroll , this . _handleOnScroll ) }
530+ onScroll = { Animated . forkEvent ( onScroll , this . _handleOnScroll ) }
523531 />
524532 )
525533 }
@@ -530,10 +538,9 @@ function KeyboardAwareHOC(ScrollableComponent: React$Component, userOptions: Key
530538// listenToKeyboardEvents(ScrollView);
531539// listenToKeyboardEvents(options)(Comp);
532540const 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 {
537544 return KeyboardAwareHOC ( configOrComp )
538545 }
539546}
0 commit comments