2016-05-13 91 views
5

升级后到0.26.0-RC版本,在iOS上这一行:阵营本地DeviceEventEmitter keyboardWillShow停止工作

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

什么都不做。当键盘打开时,从不调用updateKeyboardSpace方法。

我进口DeviceEventEmitter本:

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

我从0.21版本升级,这是工作的罚款在那里。

回答

9

It seems like you can not use this kind of event listener any more. 这似乎是handled by the Keyboard component now,它使用本机库。对于iOS it is defined here,事件名称似乎相同;不过,我找不到Android实现。您将需要测试,如果这个工程,但适用于iOS这应该做的伎俩:

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

编辑:

的API解释是内部只。对于正常使用,可以使用callbacks on the ScrollResponderYou could use eitheronKeyboardWillShowonKeyboardWillHide。 ScrollResponder Mixin用于ScrollViewListView,所以你可以在那里使用这个道具。

I did a small example on github.

+1

这看起来真棒!将尝试尽快测试! – Cherniv

+0

太棒了,让我知道;) –

+1

不能让它工作,不管我做什么它会抛出错误:* undefined不是一个对象(评估'_reactNative.Keyboard.addListener')*。这里是完整的信息:https://jsfiddle.net/fh3wq8L1/ – Cherniv

5

在Android上,您可以改用这2个事件:

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

测试的0.26.0

+0

感谢您的回答,我知道Android,它不适用于我的iOs,对不起,我没有指定我的问题 – Cherniv

+0

没问题,这只是我正在搜索Android的答案,但我没有找到任何东西,直到我通过RN代码搜索和分享在这里,以防其他人需要它的情况下 – alex88