我的React Native应用程序中的WebView出现问题。如果未为WebView指定高度,则默认为屏幕高度的一半(iPhone 6S)。但是,当我借助设置高度时Dimensions
,它显示得很好,但是只有原始的一半是交互式的,即。只能使用屏幕的上半部分滚动。
这是我当前代码的主要部分:
import React, { Component } from 'react';
import {
...
Dimensions,
...
WebView,
} from 'react-native';
let ScreenHeight = Dimensions.get("window").height;
let ScreenWidth = Dimensions.get("window").width;
class App extends Component {
render() {
return (
<View style={styles.container}>
...
<WebView
source={{uri: 'http://foo.com'}}
style={{height: ScreenHeight, width: ScreenWidth}}
/>
...
</View>
);
}
}
...
const styles = StyleSheet.create({
container: {
backgroundColor: '#bbb',
flex: 1,
},
...
});
AppRegistry.registerComponent('myApp', () => App);
我期待可以提供的任何帮助:)
伙计们,谢谢你的回答。我已经解决了我的问题,这似乎很容易解决。我基本上将包裹WebView
在自己的View
容器中。我不确定它是否有问题,因为它具有同级元素(即-NavBar
和TabBarIOS
-我从上一个片段中删除了-对不起!),但WebView
现在效果很好。
这是我的新渲染函数:
render() {
return (
<View style={styles.container}>
<NavBar>
<View>
<WebView
source={{uri: 'http://foo.com'}}
style={{height: ScreenHeight, width: ScreenWidth}}
/>
</View>
<TabBarIOS>
...
</TabBarIOS>
</View>
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句