React native: webview height
- Matan Kadosh
- 2016-02-17 01:18
- 7
Hi I know it's a known issue about the auto height of webview in react native, and I have tried all the possibles solutions I've found on the internet such as :
https://gist.github.com/epeli/10c77c1710dd137a1335
https://github.com/danrigsby/react-native-web-container/blob/master/index.js
and all the solutions suggested in: React native: Is it possible to have the height of a html content in a webview?
But unfortunately none of these seems to work for me, I understand that the workaround they all suggest is to set the title to the height, but in my case it seems that the title always stays the same which is : "text/html ...." and the rest of my html. I get the html content from an API, it comes without a body, head or html tags, I've also tried adding these tags manually to the html and nothing seems to work.
I would love to hear if anyone else had that problem and how did it get fixed.
7 Answers
I just follow this guide: https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#communicating-between-js-and-native and succeeded in my work. Here is solution: 1. Define script to send document height to native env after loaded website. 2. Handle onMesssage of webview component and reset Height via state.
const webViewScript = ` setTimeout(function() { window.postMessage(document.documentElement.scrollHeight); }, 500); true; // note: this is required, or you'll sometimes get silent failures `; ... constructor(props) { super(props); this.state = { webheight:100, } ... <WebView style={{height: this.state.webheight}} automaticallyAdjustContentInsets={false} scrollEnabled={false} source={{uri: "http://<your url>"}} onMessage={event => { this.setState({webheight: parseInt(event.nativeEvent.data)}); }} javaScriptEnabled={true} injectedJavaScript ={webViewScript} domStorageEnabled={true} ></WebView>
Hope that help!
react-native-auto-expanding-webview, Auto-expanding WebView for React Native. Contribute to shqld/react-native-auto-expanding-webview development by creating an account on GitHub. Auto-expanding WebView for React Native. Contribute to shqld/react-native-auto-expanding-webview development by creating an account on GitHub.
Tung Nguyen
2019-04-28 11:42
Apparently the problem was I had javaScriptEnabled={false}
.
After enabling it everything worked.
react-native auto height, Search for React native shop at search.sidewalk.com. See yourself. React native shop in Los Angeles Search for React native shop at search.sidewalk.com. See yourself. React native shop in Los Angeles
Matan Kadosh
2018-04-06 21:18
use package react-native-autoheight-webview
react native webview inside scrollview, I want to use WebView inside ScrollView for my react native app. But if I do so, I am not able to scroll my webview, unless I disable the scroll on scrollview. However, I need the scroll in both I want to use WebView inside ScrollView for my react native app. But if I do so, I am not able to scroll my webview, unless I disable the scroll on scrollview. However, I need the scroll in both
xiaoshitou
2019-08-16 07:55
The WebView has default styles. If you want to set height, you also need to add flex: 0
, as stated in the documentation:
Please note that there are default styles (example: you need to add flex: 0 to the style if you want to use height property).
react-native-webview npm, react-native-webview-android Simple React Native Android module to use Android's WebView inside your app (with experimental html file input support to handle file uploads in forms). react-native-webview-android Simple React Native Android module to use Android's WebView inside your app (with experimental html file input support to handle file uploads in forms).
Dirk
2019-09-24 11:38
I waste whole day to fix the height issue but in the end I had to shift to another library This is one is easy and good
react native webview onloadprogress, Override the native component used to render the WebView. Enables a custom native WebView which uses the same JavaScript as the original WebView. The nativeConfig prop expects an object with the following keys: component (any) props (object) viewManager (object) Override the native component used to render the WebView. Enables a custom native WebView which uses the same JavaScript as the original WebView. The nativeConfig prop expects an object with the following keys: component (any) props (object) viewManager (object)
Zuhair Naqi
2019-12-18 12:47
I recommend react-native-autoheight-webview. it perfect work for me. https://github.com/iou90/react-native-autoheight-webview
react-native webview flex, 95% Trial-To-Hire Success. $0 Recruiting Fee. Top 3% of World-Class Talent On Demand. Vetted React Native Developers For Your Needs. Focus On Your Project, Not Hiring. 95% Trial-To-Hire Success. $0 Recruiting Fee. Top 3% of World-Class Talent On Demand. Vetted React Native Developers For Your Needs. Focus On Your Project, Not Hiring.
donkey
2020-01-02 03:14
I wrap WebView inside a View, and set the height from the View.
react-native-webview-autoheight, Here is solution: 1. Define script to send document height to native env after loaded website. 2. Handle onMesssage of webview component and reset Height via state. React Native WebView Autoheight. React Native WebView which sets it's height automatically with minimal efforts. You can also add custom CSS style or javascript to your webview using below example.
Ali Haris
2017-02-17 15:12