2016-05-13 90 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