mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1049835b50
Summary: Simplifies `Keyboard` by removing redundant methods and changing `addEventListener` to return an `EventSubscription`. Changelog: [General][Changed] - `Keyboard.addListener` now returns an `EventSubscription` object. [General][Removed] - Removed `Keyboard.removeListener`. Instead, use the `remove()` method on the object returned by `Keyboard.addListener`. [General][Removed] - `Keyboard` no longer inherits from `NativeEventEmitter`, so it no longer implements `removeAllListeners`, and `removeSubscription`. Reviewed By: milroc Differential Revision: D26163536 fbshipit-source-id: b4bd91627cd027a13fcba269a253823913eb7589
81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
* @emails oncall+react_native
|
|
*/
|
|
|
|
const LayoutAnimation = require('../../../LayoutAnimation/LayoutAnimation');
|
|
const dismissKeyboard = require('../../../Utilities/dismissKeyboard');
|
|
const Keyboard = require('../Keyboard');
|
|
|
|
jest.mock('../../../LayoutAnimation/LayoutAnimation');
|
|
jest.mock('../../../Utilities/dismissKeyboard');
|
|
|
|
describe('Keyboard', () => {
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('uses dismissKeyboard utility', () => {
|
|
Keyboard.dismiss();
|
|
expect(dismissKeyboard).toHaveBeenCalled();
|
|
});
|
|
|
|
describe('scheduling layout animation', () => {
|
|
const scheduleLayoutAnimation = (duration, easing): void =>
|
|
// $FlowFixMe[incompatible-call]
|
|
Keyboard.scheduleLayoutAnimation({duration, easing});
|
|
|
|
it('triggers layout animation', () => {
|
|
scheduleLayoutAnimation(12, 'spring');
|
|
expect(LayoutAnimation.configureNext).toHaveBeenCalledWith({
|
|
duration: 12,
|
|
update: {
|
|
duration: 12,
|
|
type: 'spring',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('does not trigger animation when duration is null', () => {
|
|
scheduleLayoutAnimation(null, 'spring');
|
|
expect(LayoutAnimation.configureNext).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('does not trigger animation when duration is 0', () => {
|
|
scheduleLayoutAnimation(0, 'spring');
|
|
expect(LayoutAnimation.configureNext).not.toHaveBeenCalled();
|
|
});
|
|
|
|
describe('animation update type', () => {
|
|
const assertAnimationUpdateType = type =>
|
|
expect(LayoutAnimation.configureNext).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
duration: expect.anything(),
|
|
update: {duration: expect.anything(), type},
|
|
}),
|
|
);
|
|
|
|
it('retrieves type from LayoutAnimation', () => {
|
|
scheduleLayoutAnimation(12, 'linear');
|
|
assertAnimationUpdateType('linear');
|
|
});
|
|
|
|
it("defaults to 'keyboard' when key in LayoutAnimation is not found", () => {
|
|
scheduleLayoutAnimation(12, 'some-unknown-animation-type');
|
|
assertAnimationUpdateType('keyboard');
|
|
});
|
|
|
|
it("defaults to 'keyboard' when easing is null", () => {
|
|
scheduleLayoutAnimation(12, null);
|
|
assertAnimationUpdateType('keyboard');
|
|
});
|
|
});
|
|
});
|
|
});
|