[英]Expo Android: Why does the view move up when the keyboard appears?
我已將softwareKeyboardLayoutMode
字段設置為在 app.json 中pan
,如下所示:
"android": {
"softwareKeyboardLayoutMode": "pan"
},
這有效地防止了當鍵盤出現時視圖被其他組件扭曲。 但是,這會導致一種奇怪的行為,即視圖(包括堆棧屏幕標題)被鍵盤向上推,以獲取<TextInput />
出現在鍵盤區域范圍內的組件。
刪除app.json
中的softwareKeyboardLayoutMode
字段(允許它默認為resize
)可以防止這種行為,但會導致其他組件在鍵盤渲染時出現扭曲的視圖。 想知道是否有人以前遇到過這個問題,並找到了有效的解決方法/解決方案? 真的很感謝你的時間!
以下是一個最小示例的代碼:
<View style={{ flex: 1, backgroundColor: "white" }}>
<View
style={{
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 50,
backgroundColor: "silver",
}}
>
<TextInput />
</View>
</View>
你在使用 React Native 嗎? 您的應用程序中的代碼是否與您的示例相似? 鑒於提供的信息/上下文,我認為您可能希望首先嘗試添加 SafeAreaView 並將您的 View 內容包裝在其中。 下面的代碼示例使用您上面的示例:
import { SafeAreaView } from "react-native";
//all other code here to render screen
<SafeAreaView>
<View style={{ flex: 1, backgroundColor: "white" }}>
<View
style={{
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 50,
backgroundColor: "silver",
}}
>
<TextInput />
</View>
</View>
</SafeAreaView>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.