【发布时间】:2019-12-01 04:22:46
【问题描述】:
我不希望键盘在打字时将视图向上推。键盘有足够的空间不推动覆盖层,但它仍在这样做。我尝试在覆盖层内外使用keyboardavoidingview定位和填充,但没有运气。
render() {
return (
<Overlay
isVisible={this.state.isVisible}
width="auto"
height="auto"
overlayStyle={{ width: "90%", height: "50%", marginBottom: "70%" }}
>
<View>
<Text>Schedule</Text>
<TextInput
label="Event"
style={{ width: "95%", margin: "3%" }}
theme={{ colors: { primary: Themes.primaryTheme } }}
/>
<TextInput
label="Date & Time"
style={{ width: "95%", margin: "3%" }}
theme={{ colors: { primary: Themes.primaryTheme } }}
/>
<TextInput
label="Location"
style={{ width: "95%", margin: "3%" }}
theme={{ colors: { primary: Themes.primaryTheme } }}
/>
<View style={{ flexDirection: "row" }}>
<Button
mode="text"
style={{ width: "40%", margin: "3%" }}
onPress={() => this.setState({ isVisible: false })}
>
Cancel
</Button>
<Button
mode="contained"
style={{ width: "40%", margin: "3%" }}
onPress={() => this.setState({ isVisible: false })}
>
Create
</Button>
</View>
</View>
</Overlay>
);
}
【问题讨论】:
-
keyboardavoidingview在android中的行为很奇怪,您可以创建一个自定义keyboardavoidingview并为android使用一个简单的View。 -
@PooyaHaratian 我该怎么做?会不会更麻烦?
-
是的,我总是在键盘方面遇到一些麻烦。我不确定
Overlay是否在内部使用KeyboardAvoidingView(如果有,我想你应该忘记它)。如果没有,您可以尝试检查设备操作系统,iOS 使用KeyboardAvoiding,Android 使用View。或者只是尝试为每个人找到适当的行为。主要问题是它们在每个操作系统中的工作方式不同。
标签: javascript react-native react-native-elements