Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class KeyboardImpl {
listener: (...KeyboardEventDefinitions[K]) => unknown,
context?: unknown,
): EventSubscription {
return this._emitter.addListener(eventType, listener);
return this._emitter.addListener(eventType, listener, context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @format
*/

const RCTDeviceEventEmitter =
require('../../../EventEmitter/RCTDeviceEventEmitter').default;
const LayoutAnimation =
require('../../../LayoutAnimation/LayoutAnimation').default;
const dismissKeyboard = require('../../../Utilities/dismissKeyboard').default;
Expand All @@ -26,6 +28,25 @@ describe('Keyboard', () => {
expect(dismissKeyboard).toHaveBeenCalled();
});

it('invokes listeners with the specified context', () => {
const context = {};
let that;
const listener = jest.fn(function (this: unknown, _event: unknown) {
that = this;
});
const subscription = Keyboard.addListener(
'keyboardDidShow',
listener,
context,
);

RCTDeviceEventEmitter.emit('keyboardDidShow', {});

expect(listener).toHaveBeenCalled();
expect(that).toBe(context);
subscription.remove();
});

describe('scheduling layout animation', () => {
const scheduleLayoutAnimation = (
duration: null | number,
Expand Down
Loading