Skip to content

Commit 4d33080

Browse files
sahrensfacebook-github-bot
authored andcommitted
better Keyabord event utils
Reviewed By: shergin Differential Revision: D6639418 fbshipit-source-id: ef973cfebb94325579525bdcd3990737fe576ef8
1 parent f9e742a commit 4d33080

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

Libraries/Components/Keyboard/Keyboard.js

+33-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
'use strict';
1313

14+
const LayoutAnimation = require('LayoutAnimation');
1415
const invariant = require('fbjs/lib/invariant');
1516
const NativeEventEmitter = require('NativeEventEmitter');
1617
const 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
141152
Keyboard = KeyboardEventEmitter;
142153
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+
};
143166

144167
module.exports = Keyboard;

0 commit comments

Comments
 (0)