【问题标题】:React Native WebView is not loading the sourceReact Native WebView 未加载源
【发布时间】:2016-02-17 11:01:42
【问题描述】:

我正在关注 react-native 文档中的示例,但不知道为什么我的 webview 无法加载网站。

这是我的代码:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'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;

现在我所看到的只是一个指示正在加载的东西的微调器。但什么都没有改变。

我做错了什么?

根据评论者的说法,这似乎是一个基本问题,我已经为此打开了一个 GH Issue,请随时贡献 https://github.com/facebook/react-native/issues/5974

【问题讨论】:

  • 不,我用纯 html 代码试了一下,它也说正在加载。我猜RN有bug,试试在github上开一个issue。
  • 我会这样做并将链接粘贴到这里
  • @noa-dev 我试图重现这个问题。 CStyle 的内容是什么? var CStyles = require('./CStyle');这个例子出自哪里?
  • 文件 CStyle 仅包含一个导出的对象,用作样式表。

标签: webview react-native


【解决方案1】:

我遇到了和你一样的问题,虽然我不确定如何或为什么,但只需将 startInLoadingState 更改为 false 即可在我的测试设备上修复它。

【讨论】:

  • 我很确定我试过了。但我今晚会试一试:)
  • 这很糟糕,但值得一试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-14
  • 1970-01-01
相关资源
最近更新 更多