11
11
*/
12
12
'use strict' ;
13
13
14
+ const LayoutAnimation = require ( 'LayoutAnimation' ) ;
14
15
const invariant = require ( 'fbjs/lib/invariant' ) ;
15
16
const NativeEventEmitter = require ( 'NativeEventEmitter' ) ;
16
17
const KeyboardObserver = require ( 'NativeModules' ) . KeyboardObserver ;
@@ -25,16 +26,18 @@ type KeyboardEventName =
25
26
| 'keyboardWillChangeFrame'
26
27
| 'keyboardDidChangeFrame' ;
27
28
28
- type KeyboardEventData = {
29
- endCoordinates : {
30
- width : number ,
31
- height : number ,
32
- screenX : number ,
33
- screenY : number ,
34
- } ,
35
- } ;
29
+ export type KeyboardEvent = { |
30
+ + duration ? : number ,
31
+ + easing ? : string ,
32
+ + endCoordinates : { |
33
+ + width : number ,
34
+ + height : number ,
35
+ + screenX : number ,
36
+ + screenY : number ,
37
+ | } ,
38
+ | } ;
36
39
37
- type KeyboardEventListener = ( e : KeyboardEventData ) => void ;
40
+ type KeyboardEventListener = ( e : KeyboardEvent ) => void ;
38
41
39
42
// The following object exists for documentation purposes
40
43
// Actual work happens in
@@ -134,11 +137,31 @@ let Keyboard = {
134
137
*/
135
138
dismiss ( ) {
136
139
invariant ( false , 'Dummy method used for documentation' ) ;
137
- }
140
+ } ,
141
+
142
+ /**
143
+ * Useful for syncing TextInput (or other keyboard accessory view) size of
144
+ * position changes with keyboard movements.
145
+ */
146
+ scheduleLayoutAnimation ( event : KeyboardEvent ) {
147
+ invariant ( false , 'Dummy method used for documentation' ) ;
148
+ } ,
138
149
} ;
139
150
140
151
// Throw away the dummy object and reassign it to original module
141
152
Keyboard = KeyboardEventEmitter ;
142
153
Keyboard . dismiss = dismissKeyboard ;
154
+ Keyboard . scheduleLayoutAnimation = function ( event : KeyboardEvent ) {
155
+ const { duration, easing} = event ;
156
+ if ( duration ) {
157
+ LayoutAnimation . configureNext ( {
158
+ duration : duration ,
159
+ update : {
160
+ duration : duration ,
161
+ type : ( easing && LayoutAnimation . Types [ easing ] ) || 'keyboard' ,
162
+ } ,
163
+ } ) ;
164
+ }
165
+ } ;
143
166
144
167
module . exports = Keyboard ;
0 commit comments