Permalink
Browse files

better Keyabord event utils

Reviewed By: shergin

Differential Revision: D6639418

fbshipit-source-id: ef973cfebb94325579525bdcd3990737fe576ef8
  • Loading branch information...
sahrens authored and facebook-github-bot committed Dec 28, 2017
1 parent f9e742a commit 4d33080f0fa7b2eb7b0e9ff7bbd50c222f461786
Showing with 33 additions and 10 deletions.
  1. +33 −10 Libraries/Components/Keyboard/Keyboard.js
@@ -11,6 +11,7 @@
*/
'use strict';
const LayoutAnimation = require('LayoutAnimation');
const invariant = require('fbjs/lib/invariant');
const NativeEventEmitter = require('NativeEventEmitter');
const KeyboardObserver = require('NativeModules').KeyboardObserver;
@@ -25,16 +26,18 @@ type KeyboardEventName =
| 'keyboardWillChangeFrame'
| 'keyboardDidChangeFrame';
type KeyboardEventData = {
endCoordinates: {
width: number,
height: number,
screenX: number,
screenY: number,
},
};
export type KeyboardEvent = {|
+duration?: number,
+easing?: string,
+endCoordinates: {|
+width: number,
+height: number,
+screenX: number,
+screenY: number,
|},
|};
type KeyboardEventListener = (e: KeyboardEventData) => void;
type KeyboardEventListener = (e: KeyboardEvent) => void;
// The following object exists for documentation purposes
// Actual work happens in
@@ -134,11 +137,31 @@ let Keyboard = {
*/
dismiss() {
invariant(false, 'Dummy method used for documentation');
}
},
/**
* Useful for syncing TextInput (or other keyboard accessory view) size of
* position changes with keyboard movements.
*/
scheduleLayoutAnimation(event: KeyboardEvent) {
invariant(false, 'Dummy method used for documentation');
},
};
// Throw away the dummy object and reassign it to original module
Keyboard = KeyboardEventEmitter;
Keyboard.dismiss = dismissKeyboard;
Keyboard.scheduleLayoutAnimation = function(event: KeyboardEvent) {
const {duration, easing} = event;
if (duration) {
LayoutAnimation.configureNext({
duration: duration,
update: {
duration: duration,
type: (easing && LayoutAnimation.Types[easing]) || 'keyboard',
},
});
}
};
module.exports = Keyboard;

0 comments on commit 4d33080

Please sign in to comment.