[5.x] Made WebView an optional dependency which can be passed as a prop to <HTML> to support iframes #301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi 👋
This PR makes the WebView component optional, so you can choose to include it or not. I'll try to explain my reasoning about why
WebView
is preferably optional for this package.react-native-webview
component, which is installed when installingreact-native-render-html
. Linking packages unnecessary creates a problem as it often requires additional OS permissions or usage strings. It may cause your deploy to the App or Play store to fail. And obviously it also increases your binary size.react-native-render-html
is a great way to render rich-content without requiring something heavy like a webview. It is this aspect which makes this library so damn useful and appealing.react-native-webview
, this project becomes less compatible with older react-native versions, as well as requires more maintenance to keep thewebview
dependency up to date (there is already 4 PRs concerning webview-package updates).I therefore suggest an opt-in approach, where people that are using
iframe
s can specify theWebView
component that shall be used. The iframe-renderer then takes the WebView component and renders the content. When no WebView is specified to<HTML>
, but a iframe is renderered nonetheless, a warning is written to the console (Unable to render <iframe>, please specify the WebView prop in <HTML>
).For the latest react-native versions you would then use it like this (when you need iframes):
And for older react-native versions you import WebView from react-native itself:
And obviously, if you don't use iframes, then just leave it out:
Cheers and thank you for this library!