@@ -4,21 +4,23 @@ import { PropTypes } from 'react'
4
4
import ReactNative , { TextInput , Keyboard , UIManager } from 'react-native'
5
5
import TimerMixin from 'react-timer-mixin'
6
6
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
10
10
11
11
const KeyboardAwareMixin = {
12
12
mixins : [ TimerMixin ] ,
13
13
propTypes : {
14
14
enableAutoAutomaticScroll : PropTypes . bool ,
15
15
extraHeight : PropTypes . number ,
16
+ extraScrollHeight : PropTypes . number ,
16
17
} ,
17
18
18
19
getDefaultProps : function ( ) {
19
20
return {
20
- enableAutoAutomaticScroll : true ,
21
- extraHeight : _KAM_EXTRA_HEIGHT ,
21
+ enableAutoAutomaticScroll : true ,
22
+ extraHeight : _KAM_EXTRA_HEIGHT ,
23
+ extraScrollHeight : 0 ,
22
24
}
23
25
} ,
24
26
@@ -42,43 +44,40 @@ const KeyboardAwareMixin = {
42
44
43
45
// Keyboard actions
44
46
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} )
49
52
// Automatically scroll to focused TextInput
50
53
if ( this . props . enableAutoAutomaticScroll ) {
51
54
const currentlyFocusedField = TextInput . State . currentlyFocusedField ( )
52
55
if ( ! currentlyFocusedField ) {
53
56
return
54
57
}
55
-
56
58
UIManager . viewIsDescendantOf (
57
59
currentlyFocusedField ,
58
60
this . getScrollResponder ( ) . getInnerViewNode ( ) ,
59
61
( isAncestor ) => {
60
62
if ( isAncestor ) {
61
63
// Check if the TextInput will be hidden by the keyboard
62
64
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 ) {
64
66
this . scrollToFocusedInputWithNodeHandle ( currentlyFocusedField )
65
67
}
66
68
} )
67
69
}
68
70
}
69
71
)
70
72
}
71
-
72
73
if ( ! this . resetCoords ) {
73
74
this . defaultResetScrollToCoords = this . position
74
75
}
75
76
} ,
76
77
77
78
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} )
82
81
// Reset scroll position after keyboard dismissal
83
82
if ( this . resetCoords ) {
84
83
this . scrollToPosition ( this . resetCoords . x , this . resetCoords . y , true )
@@ -117,7 +116,7 @@ const KeyboardAwareMixin = {
117
116
118
117
scrollToFocusedInputWithNodeHandle : function ( nodeID : number , extraHeight : number = this . props . extraHeight ) {
119
118
const reactNode = ReactNative . findNodeHandle ( nodeID )
120
- this . scrollToFocusedInput ( reactNode , extraHeight )
119
+ this . scrollToFocusedInput ( reactNode , extraHeight + this . props . extraScrollHeight )
121
120
} ,
122
121
123
122
position: { x : 0 , y : 0 } ,
0 commit comments