1111 */
1212'use strict' ;
1313
14+ const LayoutAnimation = require ( 'LayoutAnimation' ) ;
1415const invariant = require ( 'fbjs/lib/invariant' ) ;
1516const NativeEventEmitter = require ( 'NativeEventEmitter' ) ;
1617const KeyboardObserver = require ( 'NativeModules' ) . KeyboardObserver ;
@@ -25,16 +26,18 @@ type KeyboardEventName =
2526 | 'keyboardWillChangeFrame'
2627 | 'keyboardDidChangeFrame' ;
2728
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+ | } ;
3639
37- type KeyboardEventListener = ( e : KeyboardEventData ) => void ;
40+ type KeyboardEventListener = ( e : KeyboardEvent ) => void ;
3841
3942// The following object exists for documentation purposes
4043// Actual work happens in
@@ -134,11 +137,31 @@ let Keyboard = {
134137 */
135138 dismiss ( ) {
136139 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+ } ,
138149} ;
139150
140151// Throw away the dummy object and reassign it to original module
141152Keyboard = KeyboardEventEmitter ;
142153Keyboard . 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+ } ;
143166
144167module . exports = Keyboard ;
0 commit comments