admin管理员组文章数量:1356892
I have WebView content are which changes it's height depending on amount of content. So I found a way how to take the height of the content through the document.title attribute onNavigationStateChange. Looks like this:
let html = '<!DOCTYPE html><html><body><script>document.title = document.height;</script></body></html>';
And on onNavigationStateChange
onNavigationStateChange(navState) {
this.setState({
height: navState.title
});
console.log("DATA");
console.log(this.state.height)
}
On the actual WebView render I do:
<WebView style={this._setWebviewHeight()}
automaticallyAdjustContentInsets={false}
scrollEnabled={false}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
html={html}>
</WebView>
Where:
_setWebviewHeight() {
return {
height: this.state.height,
padding: 20,
}
}
And in this case I'm getting error and I am not able to get the height of content through state. What shall I do then?
The idea of solution is taken from here: React native: Is it possible to have the height of a html content in a webview?
I have WebView content are which changes it's height depending on amount of content. So I found a way how to take the height of the content through the document.title attribute onNavigationStateChange. Looks like this:
let html = '<!DOCTYPE html><html><body><script>document.title = document.height;</script></body></html>';
And on onNavigationStateChange
onNavigationStateChange(navState) {
this.setState({
height: navState.title
});
console.log("DATA");
console.log(this.state.height)
}
On the actual WebView render I do:
<WebView style={this._setWebviewHeight()}
automaticallyAdjustContentInsets={false}
scrollEnabled={false}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
html={html}>
</WebView>
Where:
_setWebviewHeight() {
return {
height: this.state.height,
padding: 20,
}
}
And in this case I'm getting error and I am not able to get the height of content through state. What shall I do then?
The idea of solution is taken from here: React native: Is it possible to have the height of a html content in a webview?
Share Improve this question edited May 23, 2017 at 11:53 CommunityBot 11 silver badge asked Dec 24, 2015 at 14:32 Rostyslav TrocyukRostyslav Trocyuk 891 gold badge1 silver badge8 bronze badges 1- What is the error you get? – rmevans9 Commented Dec 26, 2015 at 3:36
2 Answers
Reset to default 2I have found the solution in the implementation of one of the RN third party libraries. Here is the link to it: https://github./danrigsby/react-native-web-container/blob/master/index.js
With this kind of approach all worked good.
Just try this lib: https://github./iou90/react-native-autoheight-webview It will works both on iOS & Android
本文标签: javascriptReact Native dynamic webview heightStack Overflow
版权声明:本文标题:javascript - React Native dynamic webview height - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744044062a2581197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论