react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[WebView] WebView not loading source / Staying in loading state

Open derNoaa opened this issue 10 years ago • 38 comments

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;

derNoaa avatar Feb 17 '16 11:02 derNoaa

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-native or 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!

facebook-github-bot avatar Feb 17 '16 11:02 facebook-github-bot

+1

ghamaide avatar Feb 17 '16 12:02 ghamaide

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

fakefish avatar Feb 19 '16 15:02 fakefish

Source has to be source={{ uri: YOUR_URL }}, whereas URL was just url={YOUR_URL}

tomauty avatar Feb 22 '16 16:02 tomauty

Thanks @tomauty

fakefish avatar Feb 23 '16 07:02 fakefish

@tomauty I am using {{uri: this.state.url }} and yet still it doesn't work

derNoaa avatar Feb 23 '16 07:02 derNoaa

Any errors in Safari's developer console pointing to the simulator?

tomauty avatar Feb 23 '16 19:02 tomauty

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.

derNoaa avatar Feb 24 '16 11:02 derNoaa

push

derNoaa avatar Mar 04 '16 10:03 derNoaa

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.

yuhengqiu avatar Mar 15 '16 15:03 yuhengqiu

I was trying to reproduce this issue. where is the content for CStyle? var CStyles = require('./CStyle');

zipzit avatar Apr 28 '16 01:04 zipzit

Just some Basic Styling. I use it at an implemented style sheet

derNoaa avatar Apr 28 '16 06:04 derNoaa

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 :)

derNoaa avatar Apr 28 '16 06:04 derNoaa

i'm having the same issue :(

cjmling avatar Sep 29 '16 12:09 cjmling

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 avatar Sep 29 '16 23:09 matthewvincent

Also not showing when nested inside of a View, works when it's alone.

Ehesp avatar Nov 03 '16 09:11 Ehesp

+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>

NoelBroda avatar Nov 27 '16 04:11 NoelBroda

Here a RNPlay! https://rnplay.org/apps/xMm3OQ

NoelBroda avatar Nov 27 '16 04:11 NoelBroda

Workarround:

                {
                    !this.state.showBrowser &&
                    <View>
                        <Text>xxx</Text>
                    </View>
                }

                {
                    this.state.showBrowser &&
                    <WebView
                        source={{uri: this.state.url}}
                    </WebView>
                }

NoelBroda avatar Nov 27 '16 05:11 NoelBroda

In my case an alignItems: 'center' in the parent container was causing the problem.

bvolpato avatar Jan 16 '17 08:01 bvolpato