react-native: [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;
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 38 (6 by maintainers)
Links to this issue
Commits related to this issue
- iOS: WebView stays in loading state See https://github.com/facebook/react-native/issues/5974. — committed to johncblandii/react-native by johncblandii 6 years ago
In my case an
alignItems: 'center'
in the parent container was causing the problem.I think this issue should not be closed. It can only work when at top level, but not work under a <View> tag.
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?
@matthewvincent when it’s nested inside a View component,you setting flex : 1 and webview’s flex : 1,it does work
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.
react-native
or for more real time interactions, ask on Discord in the #react-native channel.This is still an issue, but only on iOS. Android works perfectly fine. The issue is a hidden
UIWebView
never exits the loading state.React Native: 0.52.2 iOS: 11.3
Can we get this reopened, @hramos?
Logging RCTWebView’s webView.loading
I added a simple logging statement and it logs:
That’s the only log it gets when
startInLoadingState={true}
on JS. If I turn that off, you’ll see a list ofTRUE, TRUE
then aFALSE, FALSE
which then renders the UI.The Fix
In
WebView.ios.js
, editing thehidden
style fixes the loading:Originally the
height
is0
.My Component
Even I tried everything mentioned in the thread but nothing worked for me. At the end, I switched over to https://github.com/react-native-china/react-native-webkit-webview that uses WKWebView instead of UIWebView as recommended by apple for iOS 8 and above, and everything started working normally.
Having a similar issue with the
WebView
on a physical Android device, OnePlus 3T.startInLoadingState
renders the loading state, but the content never loads … unless I switch the WiFi on or off, then the WebView content loads instantly.That seems like a reasonable workaround.
Also not showing when nested inside of a View, works when it’s alone.