Created
July 15, 2016 11:37
-
-
Save norfish/653c0de319cf079a9b70011a11ee6edf to your computer and use it in GitHub Desktop.
keyboard events - rn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//安卓不支持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