Cherniv Cherniv - 1 year ago 324
Javascript Question

React Native DeviceEventEmitter keyboardWillShow stopped working

After upgrade to 0.26.0-rc version, this line:

DeviceEventEmitter.addListener('keyboardWillShow', (e)=>this.updateKeyboardSpace(e));

does nothing. When keyboard is open,
method is never called.

I'm importing DeviceEventEmitter with this:

import React from 'react';
import {DeviceEventEmitter} from 'react-native';

I upgraded from version 0.21 , it was working fine there.


It seems like you can not use this kind of event listener any more. This seems to be handled by the Keyboard component now, which uses native libraries. For iOS it is defined here, the event names seem to be the same; I couldn't find an Android implementation, though. You would need to test if this works, but for iOS this should do the trick:

import {Keyboard}  from 'react-native';
Keyboard.addListener('keyboardWillShow', (e)=>this.updateKeyboardSpace(e));


The API explained was internal only. For normal usage, one could use the callbacks on the ScrollResponder. You could use either onKeyboardWillShow and onKeyboardWillHide. The ScrollResponder Mixin is used in the ScrollView and ListView, so you may use this props there.

I did a small example on github.