Why is the iframe within a react native webview on iOS not rendering content?
For showing static HTML or inline HTML, you need to set originWhiteList
to *
import { WebView } from 'react-native-webview';
class MyInlineWeb extends Component {
render() {
return (
<WebView
originWhitelist={['*']}
source={{ html: '<h1>Hello world</h1>' }} />
);
}
}
Similar to the example above you can load an iFrame inside of a WebView.
import { WebView } from 'react-native-webview';
class MyInlineWeb extends Component {
render() {
return (
<WebView
originWhitelist={['*']}
source={{ html: "<iFrame src='your_URL' />" }} />
);
}
}
So as shown in the example above, your iFrame is loaded inside the WebView component. You can then render any web page or URL inside your iFrame then.
iFrame refused to load inside a React Native Webview
If anyone stumbles on this, the error was due to the fact that I was loading the iFrame in an about:blank (created by react-native-webview) and this is not supported by CSP.
I had to host a real blank page somewhere to embed the iFrame inside and I got it working!
How to use Iframe in react native?
I answer on my question.
I used webview for display Iframe.
<WebView
source={{html: '<iframe width="100%" height="50%" src="https://www.youtube.com/embed/cqyziA30whE" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'}}
style={{marginTop: 20}}
/>
react-native-webview control media playback in iframe
For those who also might find themselves in a similar situation, I ended up solving this by making use of Vimeo's player.js API and injecting the necessary JS to react-native-webview
.
https://github.com/vimeo/player.js/tree/ccc4d670bf81544710b23c22910ed2f75f62696f#pause-promisevoid-passworderrorprivacyerrorerror
https://github.com/react-native-webview/react-native-webview/blob/eb4e923fb012f1dcb5c5389fb1901ee84e32fa8c/docs/Reference.md#injectjavascriptstr
https://github.com/react-native-webview/react-native-webview/blob/eb4e923fb012f1dcb5c5389fb1901ee84e32fa8c/docs/Guide.md#communicating-between-js-and-native
Facebook like button iframe appears very small on react-native webview
You can set the scalesPageToFit to false like this. Setting width and height to "100%" lets the iframe to take in as much space available.
<SafeAreaView style={{flex: 1}}>
<WebView
source={{
html:
'<iframe src="https://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2FGalarmApp%2F&width=200&layout=standard&action=like&size=large&share=false&height=35&appId=1010058565805776" width="100%" height="100%" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>'
}}
scalesPageToFit={false}
/>
</SafeAreaView>
Related Topics
Filter: Progid:Dximagetransform.Microsoft.Gradient Is Not Working in Ie7
How to Get The Cursor to Change to The Hand When Hovering a <Button> Tag
Em Vs Px... for Mobile Browsers
Stretch List Items <Li> to Fill The Width of <Ul>
CSS for a Sidebar Menu That Folds in and Out
Bootstrap 3.0 Affix with List Changes Width
How to "Snap to Pixel" After a CSS Translate
Javafx 2 and CSS Pseudo-Classes: Setting Hover Attributes in Setstyle Method
Why Won't Opera (11.00) Display Custom (@Font-Face) Fonts
CSS Table Border Spacing Inside Only
How to Increase Bootstrap 3 Navbar Height While Keeping Menu Height Small When Collapsed
Webpack - Require('Node_Modules/Leaflet/Leaflet.CSS')
How to Make The Body Width Equal to The Device-Width Automatically in CSS3 Media Query
Mattooltipclass Not Applying CSS
Linear Fade Out Div, Content and Border (Solid at Top to Transparent at Bottom)
Body { Font-Size: 100.01%; } Vs Body { Font-Size: 100%; }
Two Divs Inside Div. How to Auto-Fill The Space of Parent Div by Second Div
Browser-Specific Prefixes with a CSS Transition on Transform