@@ -4,21 +4,23 @@ import { PropTypes } from 'react'
44import ReactNative , { TextInput , Keyboard , UIManager } from 'react-native'
55import TimerMixin from 'react-timer-mixin'
66
7- const _KAM_DEFAULT_TAB_BAR_HEIGHT = 49
8- const _KAM_KEYBOARD_OPENING_TIME = 250
9- const _KAM_EXTRA_HEIGHT = 75
7+ const _KAM_DEFAULT_TAB_BAR_HEIGHT : number = 49
8+ const _KAM_KEYBOARD_OPENING_TIME : number = 250
9+ const _KAM_EXTRA_HEIGHT : number = 75
1010
1111const KeyboardAwareMixin = {
1212 mixins : [ TimerMixin ] ,
1313 propTypes : {
1414 enableAutoAutomaticScroll : PropTypes . bool ,
1515 extraHeight : PropTypes . number ,
16+ extraScrollHeight : PropTypes . number ,
1617 } ,
1718
1819 getDefaultProps : function ( ) {
1920 return {
20- enableAutoAutomaticScroll : true ,
21- extraHeight : _KAM_EXTRA_HEIGHT ,
21+ enableAutoAutomaticScroll : true ,
22+ extraHeight : _KAM_EXTRA_HEIGHT ,
23+ extraScrollHeight : 0 ,
2224 }
2325 } ,
2426
@@ -42,43 +44,40 @@ const KeyboardAwareMixin = {
4244
4345 // Keyboard actions
4446 updateKeyboardSpace: function ( frames : Object ) {
45- const keyboardSpace = ( this . props . viewIsInsideTabBar ) ? frames . endCoordinates . height - _KAM_DEFAULT_TAB_BAR_HEIGHT : frames . endCoordinates . height
46- this . setState ( {
47- keyboardSpace : keyboardSpace ,
48- } )
47+ let keyboardSpace : number = frames . endCoordinates . height + this . props . extraScrollHeight
48+ if ( this . props . viewIsInsideTabBar ) {
49+ keyboardSpace -= _KAM_DEFAULT_TAB_BAR_HEIGHT
50+ }
51+ this . setState ( { keyboardSpace} )
4952 // Automatically scroll to focused TextInput
5053 if ( this . props . enableAutoAutomaticScroll ) {
5154 const currentlyFocusedField = TextInput . State . currentlyFocusedField ( )
5255 if ( ! currentlyFocusedField ) {
5356 return
5457 }
55-
5658 UIManager . viewIsDescendantOf (
5759 currentlyFocusedField ,
5860 this . getScrollResponder ( ) . getInnerViewNode ( ) ,
5961 ( isAncestor ) => {
6062 if ( isAncestor ) {
6163 // Check if the TextInput will be hidden by the keyboard
6264 UIManager . measureInWindow ( currentlyFocusedField , ( x , y , width , height ) => {
63- if ( y + height > frames . endCoordinates . screenY ) {
65+ if ( y + height > frames . endCoordinates . screenY - this . props . extraScrollHeight - this . props . extraHeight ) {
6466 this . scrollToFocusedInputWithNodeHandle ( currentlyFocusedField )
6567 }
6668 } )
6769 }
6870 }
6971 )
7072 }
71-
7273 if ( ! this . resetCoords ) {
7374 this . defaultResetScrollToCoords = this . position
7475 }
7576 } ,
7677
7778 resetKeyboardSpace : function ( ) {
78- const keyboardSpace = ( this . props . viewIsInsideTabBar ) ? _KAM_DEFAULT_TAB_BAR_HEIGHT : 0
79- this . setState ( {
80- keyboardSpace : keyboardSpace ,
81- } )
79+ const keyboardSpace : number = ( this . props . viewIsInsideTabBar ) ? _KAM_DEFAULT_TAB_BAR_HEIGHT : 0
80+ this . setState ( { keyboardSpace} )
8281 // Reset scroll position after keyboard dismissal
8382 if ( this . resetCoords ) {
8483 this . scrollToPosition ( this . resetCoords . x , this . resetCoords . y , true )
@@ -117,7 +116,7 @@ const KeyboardAwareMixin = {
117116
118117 scrollToFocusedInputWithNodeHandle : function ( nodeID : number , extraHeight : number = this . props . extraHeight ) {
119118 const reactNode = ReactNative . findNodeHandle ( nodeID )
120- this . scrollToFocusedInput ( reactNode , extraHeight )
119+ this . scrollToFocusedInput ( reactNode , extraHeight + this . props . extraScrollHeight )
121120 } ,
122121
123122 position: { x : 0 , y : 0 } ,
0 commit comments