![](/img/trans.png)
[英]React Native Android TextInput issue when using useSafeArea Hook
[英]There is an issue for using TextInput on android in react native
我在使用React本機在android上使用TextInput時遇到問題,我使用了以下代碼。
導出默認類的App擴展了Component {render(){return(
</View>
);
}}
然后屏幕如下:
當我點擊TextInput視圖時,屏幕出現,就像使用keyboardavoidingview一樣。
它在android上,但是在ios上沒有任何作用。 我沒有使用任何其他組件。
我的package.json如下:
{
"name": "example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.1",
"react-native": "0.57.7",
"react-native-gesture-handler": "^1.0.10",
"react-native-indicators": "^0.13.0",
"react-native-maps": "^0.22.1",
"react-native-maps-directions": "^1.6.0",
"react-native-modal": "^7.0.1",
"react-navigation": "^3.0.4"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.50.0",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}
在Android上,盡管我從未使用過該組件,但為什么會有類似使用KeyboardAvoidingView的效果? 為什么在ios上還可以呢? 聽到您的進步我感到非常高興。 謝謝。
每當您使用TextInput
,建議您將Scrollview
用作它的父視圖,並帶有prop keyboardShouldPersistTaps="always"
。 每當鍵盤彈出時,這將創建均勻性。
編輯:
<View style={{flex:1}}>
<ScrollView keyboardShouldPersistTaps="always">
<View style={{paddingTop:20}}> //Inside ScrollView flex doesn't work so use padding to control spacing
// Add your <TextInput> Tag here !!
</View>
</ScrollView>
</View>
希望可以為您服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.