@@ -8,7 +8,7 @@ var ScrollViewManager = NativeModules.ScrollViewManager;
8
8
export default class KeyboardAwareBase extends React . Component {
9
9
constructor ( props ) {
10
10
super ( props ) ;
11
- this . _bind ( '_onKeyboardWillShow' , '_onKeyboardWillHide' , '_addKeyboardEventListeners' , '_removeKeyboardListeners' , '_scrollToFocusedTextInput' , '_onKeyboardAwareViewLayout' , 'scrollToBottom' ) ;
11
+ this . _bind ( '_onKeyboardWillShow' , '_onKeyboardWillHide' , '_addKeyboardEventListeners' , '_removeKeyboardListeners' , '_scrollToFocusedTextInput' , '_onKeyboardAwareViewLayout' , 'scrollToBottom' , 'scrollBottomOnNextSizeChange' ) ;
12
12
this . state = { keyboardHeight : 0 } ;
13
13
}
14
14
@@ -31,13 +31,26 @@ export default class KeyboardAwareBase extends React.Component {
31
31
32
32
componentWillMount ( ) {
33
33
this . _addKeyboardEventListeners ( ) ;
34
-
35
34
}
36
35
37
36
_onKeyboardAwareViewLayout ( layout ) {
38
37
this . _keyboardAwareView . layout = layout ;
38
+ this . _keyboardAwareView . contentOffset = { x : 0 , y : 0 } ;
39
+ this . _updateKeyboardAwareViewContentSize ( ) ;
40
+ }
41
+
42
+ _onKeyboardAwareViewScroll ( contentOffset ) {
43
+ this . _keyboardAwareView . contentOffset = contentOffset ;
44
+ this . _updateKeyboardAwareViewContentSize ( ) ;
45
+ }
46
+
47
+ _updateKeyboardAwareViewContentSize ( ) {
39
48
ScrollViewManager . getContentSize ( React . findNodeHandle ( this . _keyboardAwareView ) , ( res ) => {
40
49
this . _keyboardAwareView . contentSize = res ;
50
+ if ( this . state . scrollBottomOnNextSizeChange ) {
51
+ this . scrollToBottom ( ) ;
52
+ this . state . scrollBottomOnNextSizeChange = false ;
53
+ }
41
54
} )
42
55
}
43
56
@@ -67,16 +80,23 @@ export default class KeyboardAwareBase extends React.Component {
67
80
68
81
this . setState ( { keyboardHeight : newKeyboardHeight } ) ;
69
82
}
70
-
83
+
71
84
_onKeyboardWillHide ( event ) {
85
+ const keyboardHeight = this . state . keyboardHeight ;
72
86
this . setState ( { keyboardHeight : 0 } ) ;
73
- if ( this . _keyboardAwareView ) {
74
- this . _keyboardAwareView . scrollTo ( { x : 0 , y : 0 , animated : true } ) ;
75
- }
87
+
88
+ const yOffset = Math . max ( this . _keyboardAwareView . contentOffset . y - keyboardHeight , 0 ) ;
89
+ this . _keyboardAwareView . scrollTo ( { x : 0 , y : yOffset , animated : true } ) ;
90
+ }
91
+
92
+ scrollBottomOnNextSizeChange ( ) {
93
+ this . state . scrollBottomOnNextSizeChange = true ;
76
94
}
77
95
78
96
scrollToBottom ( ) {
79
- const bottomYOffset = this . _keyboardAwareView . contentSize . height - this . _keyboardAwareView . layout . height + this . _keyboardAwareView . props . contentInset . bottom ;
80
- this . _keyboardAwareView . scrollTo ( { x : 0 , y : bottomYOffset , animated : true } ) ;
97
+ if ( this . _keyboardAwareView ) {
98
+ const bottomYOffset = this . _keyboardAwareView . contentSize . height - this . _keyboardAwareView . layout . height + this . _keyboardAwareView . props . contentInset . bottom ;
99
+ this . _keyboardAwareView . scrollTo ( { x : 0 , y : bottomYOffset , animated : true } ) ;
100
+ }
81
101
}
82
102
}
0 commit comments