我编写了一个简单的iOS程序来使用React Native显示图像.
'use strict';
var React = require('react-native');
var {
Image
} = React;
var styles = React.StyleSheet.create({
base: {
height: 400,
width: 400
}
});
class SimpleApp extends React.Component {
render() {
return (
<Image
style={styles.base}
source={require('image!k')}
//source={{uri: 'http://news.xinhuanet.com/world/2015-05/09/127782089_14311512601821n.jpg'}}
/>
)
}
}
React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
Run Code Online (Sandbox Code Playgroud)
但是我从iPad屏幕上收到了消息:
"Failed to print error:","'undefined' is not an object (evaluating 'stackString.split')"
Run Code Online (Sandbox Code Playgroud)
当我更改代码以使用图像网址时
//source={require('image!k')}
source={{uri: 'http://news.xinhuanet.com/world/2015-05/09/127782089_14311512601821n.jpg'}}
Run Code Online (Sandbox Code Playgroud)
我只得到一个红色的矩形边框.
当我使用另一个js文件时,一切运行良好."Hello World"可以在iPad屏幕上显示.
'use strict';
var React = require('react-native');
var {
Text,
} = React;
class SimpleApp extends React.Component {
render() {
return (
<Text>Hello World</Text>
)
}
}
React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
Run Code Online (Sandbox Code Playgroud)
确保您使用的是最新版本的React Native.使用React Native 0.4.4以下工作:
本地形象
<Image
style={styles.base}
source={require('image!tabnav_settings')}
/>
Run Code Online (Sandbox Code Playgroud)
还要确保将要使用的图像添加到图像资源:

远程图像
<Image
style={styles.base}
source={{uri: 'http://i.stack.imgur.com/DfkfD.png'}}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12941 次 |
| 最近记录: |