Try to use react-native-webview
:
import { WebView } from 'react-native-webview';
....
<WebView
scalesPageToFit={true}
bounces={false}
javaScriptEnabled
style={{ height: 500, width: 300 }}
source={{
html: `
<!DOCTYPE html>
<html>
<head></head> // <--add header styles if needed
<body>
<div id="baseDiv">${iframeString}</div> //<--- add your iframe here
</body>
</html>
`,
}}
automaticallyAdjustContentInsets={false}
/>
You can use an iframeString
value like:
<iframe src="https://mdn-samples.mozilla.org/snippets/html/iframe-simple-contents.html"
title="iframe Example 1" width="400" height="300">
</iframe>
Notes:
1) since source.html
param can be any html string you could also pass the iframeString
directly without any html page wrapper. In my cases I found it's easier to customize the displayed content with that outer html wrapper code.
2) known issues about iframes and rn-webview:
https://github.com/react-native-webview/react-native-webview/issues?q=iframe+is%3Aopen
3) Link to snack:
https://snack.expo.dev/@florindobre99/webview-example
More info about webview here:
https://github.com/react-native-community/react-native-webview