我从api获取html内容,我想在我的应用程序中将其呈现为Web视图.
webview组件嵌套在scrollview中,因为它在我的渲染函数上面有一些其他内容是这样的:
render() {
var html = '<!DOCTYPE html><html><body>' + this.state.pushEvent.Description + '</body></html>';
return (
<ScrollView>
<View style={styles.recipe}>
<Image source={{uri: this.state.pushEvent.ImageUrl}}
style={styles.imgFull} />
<Text style={styles.title}>{this.state.pushEvent.Title}</Text>
<WebView style={{padding: 20}}
automaticallyAdjustContentInsets={false}
scrollEnabled={false}
html={html}>
</WebView>
</View>
</ScrollView>
);
}Run Code Online (Sandbox Code Playgroud)
问题是我的html只有20pt高,这是我的填充.是否有一种聪明的方法来获得内容的高度?
我有点困惑,这个sintax有什么区别:
constructor(props) {
super(props);
this.state = {
openPane: false
}
this.togglePaneHelper = this.togglePaneHelper.bind(this);
}
componentDidMount() {
document.body.addEventListener('click', this.togglePaneHelper);
}
componentWillUnmount() {
document.body.removeEventListener('click', this.togglePaneHelper);
}
Run Code Online (Sandbox Code Playgroud)
还有这个:
constructor(props) {
super(props);
this.state = {
openPane: false
}
}
componentDidMount() {
document.body.addEventListener('click', this.togglePaneHelper.bind(this));
}
componentWillUnmount() {
document.body.removeEventListener('click', this.togglePaneHelper);
}
Run Code Online (Sandbox Code Playgroud)
我担心的是第二种语法没有正确删除列表器,它会导致此警告:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component.
Run Code Online (Sandbox Code Playgroud)