Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native DeviceEventEmitter keyboardWillShow stopped working

After upgrade to 0.26.0-rc version, on iOs this line:

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

does nothing. When keyboard is open, updateKeyboardSpace 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.

like image 492
Ivan Chernykh Avatar asked May 13 '16 11:05

Ivan Chernykh


2 Answers

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));

EDIT:

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.

like image 54
Daniel Schmidt Avatar answered Oct 19 '22 13:10

Daniel Schmidt


On android, you can use instead these 2 events:

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

tested on 0.26.0

like image 44
alex88 Avatar answered Oct 19 '22 14:10

alex88