当键盘出现在iOS上时
问题:WebView的高度不会降低iOS上的键bor时
,我使用了keyboardAvoidingView
包装我的webview
像这样
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={isKeyboardOpen ? {
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height: deviceHeight - y - keyboardHeight,
} : {
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height:
deviceHeight - y
}}
>
// webivew here
</KeyboardAvoidingView>
我偶尔当隐藏/出现键盘时,使keyboardAvoidingView
的高度动态更改。
请检查下图。我想让红色部分消失。或至少使WebView的内容适合容器的空间(keyboardAvoidingView
组件),并使其无法向下滚动。
屏幕截图/视频:
我添加style = {{backgroundColor:'red'}}
中的weview。如您所见,Webview的内容被封装为Exepeped,但Red Bacground仍然出现。
环境:
- OS:iOS
- OS版本:15.4.1
- React-Native版本:0.64.2
- React-native-webview版本:11.2.3
Problem: The height of webview doesn't reduce when I open up the keyborad on IOS
I used a KeyboardAvoidingView
wrap my Webview
like this
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={isKeyboardOpen ? {
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height: deviceHeight - y - keyboardHeight,
} : {
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height:
deviceHeight - y
}}
>
// webivew here
</KeyboardAvoidingView>
I even make the height of KeyboardAvoidingView
is dynamically change when the keyboard is hidden/appeared.
Please check the image below. I'd like to make the red section is dissapeared. Or at least make the content of webview fit into the container's space (which is KeyboardAvoidingView
component) and make it unable to scroll down.
Screenshots/Videos:
I add style={{ backgroundColor: 'red' }}
into Weview. As you can see that the webview's content is shirnked as exepected but the red bacground still appear.
Environment:
- OS: IOS
- OS version: 15.4.1
- react-native version: 0.64.2
- react-native-webview version: 11.2.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我而言。我需要防止WebView滚动。有一个属性,称为
scrolenabled
的WebView
组件的属性。代码看起来像这样In my case. I need to prevent the webview from scrolling. There is a property called
scrollEnabled
of theWebView
component that does that. The codes will look like this