[WebView] WebView not loading source / Staying in loading state
Hello,
seems like there Is an issue with the WebView not loading its source. I have followed the basic example on the DOCS and tried to load google.com and plain html. Either one didnt work. RN V0.19. Staying in loading state.
Sample code (nested component):
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
Image,
TextInput,
Button,
TouchableHighlight,
TouchableOpacity,
StatusBarIOS,
WebView
} from 'react-native';
StatusBarIOS.setStyle(1);
import Dimensions from 'Dimensions';
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;
var CStyles = require('./CStyle');
class TestComp extends Component {
constructor(){
super();
this.state = {
url: 'https://www.google.at/'
}
}
render() {
return (
<View style={{flex: 1}}>
<WebView
ref="webview"
style={{width: width}}
automaticallyAdjustContentInsets={false}
source={{uri: this.state.url}}
javaScriptEnabled={true}
domStorageEnabled={true}
decelerationRate="normal"
startInLoadingState={true}
/>
</View>
);
}
}
module.exports = TestComp;
Hey noabyuna, thanks for reporting this issue!
React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
- If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag
react-nativeor for more real time interactions, ask on Discord in the #react-native channel. - If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
- We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!
+1
the problem is when I use the old prop named url it shows a warning says url has been deprecated, use source prop in version of 0.20, but use source it says source is invalid prop
Source has to be source={{ uri: YOUR_URL }}, whereas URL was just url={YOUR_URL}
Thanks @tomauty
@tomauty I am using {{uri: this.state.url }} and yet still it doesn't work
Any errors in Safari's developer console pointing to the simulator?
Unfortunately I get no errors in chrome live debugging and no errors in the app itself. I have an open SO question regarding that issue - we can continue over there so that his doesn't get spammed.
push
I had this issue when I put webview under view. An alternative solution is to move the webview out of the view(ex: as a root view), the webview came out. I thought this issue might be related to the iteration of view, because if you check the debug navigator in Xcode, there was abnormal numbers of RCTViews by a single request.
I was trying to reproduce this issue. where is the content for CStyle?
var CStyles = require('./CStyle');
Just some Basic Styling. I use it at an implemented style sheet
The webview is nested in a regular view with a flex .9 height and a header element above it with .1 height. Nothing more to the CStyles :)
i'm having the same issue :(
Also having this issue. WebView loads when it's the only component being returned, but not when it's nested inside a View component.
[edit] I'm not sure why, but my problem seems to have been solved by setting a width property in my WebView's styling. Possibly some issue with the parent's flex property?
Also not showing when nested inside of a View, works when it's alone.
+1
This is my tree:
<View style={styles.self}>
<View style={styles.header.self}>
<Text>xxx</Text>
</View>
<View style={styles.content.self}>
{this.state.view}
</View>
<View style={styles.header.self}>
<Text>xxx</Text>
</View>
</View>
Here a RNPlay! https://rnplay.org/apps/xMm3OQ
Workarround:
{
!this.state.showBrowser &&
<View>
<Text>xxx</Text>
</View>
}
{
this.state.showBrowser &&
<WebView
source={{uri: this.state.url}}
</WebView>
}
In my case an alignItems: 'center' in the parent container was causing the problem.