Respond to native DeviceEventEmitter keyboardWillShow stopped working

After upgrading to version 0.26.0-rc on iOS, this line:

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

doing nothing. When the keyboard is open, the updateKeyboardSpace method updateKeyboardSpace never called.

I import DeviceEventEmitter with this:

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

I updated version 0.21, it worked fine there.

+5
source share
2 answers

It looks like you can no longer use this event listener. It seems to be now handled by a keyboard component that uses its own libraries. For iOS, it is defined here , the event names seem the same; However, I could not find an Android implementation. You will need to check if this works, but for iOS this should do the trick:

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

EDIT:

The API explanation was internal. For normal use, you can use callbacks in the ScrollResponder . You can use either onKeyboardWillShow , and onKeyboardWillHide . ScrollResponder Mixin is used in ScrollView and ListView , so you can use this attribute there,

I made a small example on github.

+9
source

In android you can use these 2 events:

 DeviceEventEmitter.addListener('keyboardDidShow', this.keyboardWillShow.bind(this)) DeviceEventEmitter.addListener('keyboardDidHide', this.keyboardWillHide.bind(this)) 

checked for 0.26.0

+5
source

All Articles