Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
WebView is used to display the Web Content into our Application. Web Content may be any URL or HTML data. In this blog, I have highlighted how to create a dynamic height Webview. It is the toughest and required task in react native.
The problem of React Native Webview-
React Native does not provide dynamic height to Webview Component, so we need to provide fix height to our WebView but fix height is not suitable for the Html content. If we use Webview with some other View Component then Webview takes all screen size and other views are not displayed.
How can solve it?
I have read & used some library but the issue has not solved in case. So, I have read one library “react-native-webview-autoheight” and create my own Webview Component name MyWebview. For the solution, I have used onMessage props. it is a function that is invoked when the webview calls window.postMessage. Setting this property will inject a postMessage global into your webview, but will still call pre-existing values of postMessage.
window.postMessage
postMessage
window.postMessage accepts one argument, data which will be available on the event object, event.nativeEvent.data. data must be a string.
data
event.nativeEvent.data
For this facility of Webview, I have injected the Javascript to Webview that computes the height of the content and triggered the function postMessage and pass the height of the content with this function and get this size data on onMessage props function and update the webview height state.
Source code for the injected script
Source code of My Webview-
Source code to invoke MyWebview-
References:-
https://facebook.github.io/react-native/docs/webview
https://www.npmjs.com/package/react-native-webview-autoheight
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
The results provided were above our expectations both in deliverability timeline as well as operation. They are a top-notch company with many resources and a company we feel honoured to work with again!
Lee Seward
Founder, Gro-Connect
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.