[英]React Native Android keyboard highlight text issue
在React Native上的輸入組件中突出顯示文本時遇到android問題。
重新啟動應用程序時功能還不錯,您可以打開和關閉輸入框,然后鍵入和發送消息,如下所示:
現在,當您按住文本以突出顯示它時,就會出現問題(因此您可以復制/粘貼/剪切文本):
發生這種情況后,關閉並重新打開文本框具有相同的效果(底部導航欄顯示)。 現在,在渲染下面的文本時,鍵盤似乎覆蓋在屏幕上方,就好像鍵盤已最小化一樣,無論它是否處於活動狀態。
這方面如何破壞整個鍵盤應用程序的狀態? 有人可以鏈接或通知我如何處理或訪問顯示在Android頂部的復制/粘貼功能嗎? 沒有任何意義的是,一旦發生這種情況,整個應用程序都無法通過鍵盤輸入輸入-您可以通過重新啟動應用程序使其再次運行。
相關代碼如下(如果有遺漏,請說):
DeviceEventEmitter代碼:
componentDidMount: function(){
let context = this,
DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
context.setState({
height: context.listViewMaxHeight - e.endCoordinates.height + 50,
});
});
DeviceEventEmitter.addListener('keyboardWillHide', function(e: Event) {
context.setState({
height: context.listViewMaxHeight,
})
});
}
組件渲染功能中的TextInput組件:
<View style={styles.textInputContainer}>
<TextInput
maxNumberOfLines={8}
multiline={true}
autoFocus={false}
editable={true}
numberOfLines= {5}
ref='textInput'
onChangeText={this.onChangeText}
style={[styles.textInput, {height: context.props.textInputHeight}]}
placeholder={context.props.placeholder}
placeholderTextColor="#5A5A5A"
value={context.state.text}/>
<Button
style={styles.sendButton}
onPress={this._onPress}
disabled={this.state.disabled}>
Send </Button>
</View>
解決此問題的第一部分主要解決方法是使用keyboardDidShow和keyboardDidHide而不是keyboardWillShow和keyboardWillHide。 (謝謝@pinewood)
DeviceEventEmitter.addListener('keyboardDidShow', function(e: Event) {
context.setState({
height: context.listViewMaxHeight - e.endCoordinates.height + 50,
});
});
DeviceEventEmitter.addListener('keyboardDidHide', function(e: Event) {
context.setState({
height: context.listViewMaxHeight,
})
});
第二個組件是確保使用清單來獲得所需的鍵盤功能,當前我們已更改為:
<activity android:windowSoftInputMode="stateUnspecified|adjustPan" />
鍵盤的問題在這里也有更詳細的介紹-https: //github.com/exponentjs/react-native-tab-navigator/issues/48
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.