Reactjs 图像不渲染,但在React本机Web Player上工作

Reactjs 图像不渲染,但在React本机Web Player上工作,reactjs,react-native,Reactjs,React Native,此代码在代码示例中的React本机Web播放器上运行良好: 但在运行“react native run android”之后,该应用程序会在我的手机上加载所有文本,但不会加载图像。有一个很大的差距,图像应该是,但不是一个图像!图像在网络播放器上呈现良好,所以我想知道这是否是应用程序打包的问题 App.js中的代码 /** * Sample React Native App * https://github.com/facebook/react-native * @flow */

此代码在代码示例中的React本机Web播放器上运行良好:

但在运行“react native run android”之后,该应用程序会在我的手机上加载所有文本,但不会加载图像。有一个很大的差距,图像应该是,但不是一个图像!图像在网络播放器上呈现良好,所以我想知道这是否是应用程序打包的问题

App.js中的代码

    /**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  Image,
  View,
  AppRegistry
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component {
  render() {

    let pic = {
      uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
    }

    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Image source={pic} style={styles.image} />
        <Text style={styles.instructions}>
          {instructions}
        </Text>

      </View>
    );
  }
}

AppRegistry.registerComponent('AwesomeProject', () => App);


const styles = StyleSheet.create({
  image: {
    flex: 1,
    height: null,
    width: null,
    resizeMode: 'cover'
  },
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
/**
*示例React本机应用程序
* https://github.com/facebook/react-native
*@flow
*/
从“React”导入React,{Component};
进口{
平台,
样式表,
文本,
形象,,
看法
评价学
}从“反应本机”;
const指令=Platform.select({
ios:'按Cmd+R重新加载,\n'+
“用于开发菜单的Cmd+D或shake”,
android:“双击键盘上的R以重新加载,\n”+
'为开发菜单摇动或按下菜单按钮',
});
导出默认类应用程序扩展组件{
render(){
设pic={
uri:'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
}
返回(
欢迎来到这里!
要开始,请编辑App.js
{指令}
);
}
}
AppRegistry.registerComponent('AwesomeProject',()=>App);
const styles=StyleSheet.create({
图片:{
弹性:1,
高度:空,
宽度:空,
resizeMode:“封面”
},
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”,
},
欢迎:{
尺寸:20,
textAlign:'中心',
差额:10,
},
说明:{
textAlign:'中心',
颜色:'#333333',
marginBottom:5,
},
});

因为您已经在做

justifyContent: 'center',
    alignItems: 'center',
在父容器样式中,您正在限制图像的尺寸

请将其移除,或为图像提供宽度,如图所示

const {width, height} = Dimensions.get('window')

image: {
        flex: 1,
        width,
        resizeMode: 'cover'
    }