gpt4 book ai didi

react-native - 显示键盘 react 原生时隐藏底部 ImageView

转载 作者:行者123 更新时间:2023-12-04 00:21:17 36 4
gpt4 key购买 nike

I have form Login with two textInput

And when keyboard showing...

怎么隐藏这张图。。。
感谢您的任何帮助!

最佳答案

您可以使用 Keyboard在 ReactNative 中监听键盘的变化并在键盘可见时隐藏您的图像。

检查下面的示例代码

import * as React from "react";
import { View, Keyboard, TextInput, Image } from "react-native";

export default class App extends React.Component {
state = {
isKeyboadVisible: false,
text: ""
};

componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener(
"keyboardDidShow",
this._keyboardDidShow
);
this.keyboardDidHideListener = Keyboard.addListener(
"keyboardDidHide",
this._keyboardDidHide
);
}

componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}

_keyboardDidShow = () => {
this.setState({
isKeyboadVisible: true
});
};

_keyboardDidHide = () => {
this.setState({
isKeyboadVisible: false
});
};

render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TextInput
style={{
height: 40,
width: "80%",
borderColor: "red",
borderWidth: 1,
marginBottom: 10
}}
onChangeText={text => this.setState({ text })}
value={this.state.text}
/>
{!this.state.isKeyboadVisible && (
<Image
style={{ width: 100, height: 100 }}
source={{ uri: "https://reactnative.dev/img/tiny_logo.png" }}
/>
)}
</View>
);
}
}

根据您的要求更改上述代码。

希望这对你有帮助。如有疑问,请放心。

关于react-native - 显示键盘 react 原生时隐藏底部 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60499896/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com