Skip to content

Instantly share code, notes, and snippets.

@norfish
Created July 15, 2016 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norfish/653c0de319cf079a9b70011a11ee6edf to your computer and use it in GitHub Desktop.
Save norfish/653c0de319cf079a9b70011a11ee6edf to your computer and use it in GitHub Desktop.
keyboard events - rn
//安卓不支持willShow方法,统一在didShow中处理
RCTDeviceEventEmitter.addListener(Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', evt=> {
if (!writeStore.isLoggingin) {
dispatcher.dispatch({
namespace: 'write',
action: 'keyboardShow',
data: {
keyboardHeight: evt.endCoordinates.height
}
});
}
}),
//针对搜狗输入法等第三方键盘做的兼容
//这些输入法会多次触发keyboardWillShow事件,造成定位错误
//但是他们的keyboardDidShow事件都只触发一次,因此在didShow事件中重新计算Y
RCTDeviceEventEmitter.addListener('keyboardDidShow', ()=> {
if (!writeStore.isLoggingin) {
writeStore.configureTargetY('focus')
.then(function (targetY) {
writeStore.emit('write.setScrollTop', targetY);
});
}
}),
//安卓不支持willHide方法,统一在didHide中处理
RCTDeviceEventEmitter.addListener(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', ()=> {
if (!writeStore.isLoggingin) {
dispatcher.dispatch({
namespace: 'write',
action: 'keyboardHide'
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment