I write a simple iOS program to show image with 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);
But I got the message from iPad screen:
"Failed to print error:","'undefined' is not an object (evaluating 'stackString.split')"
When I change the code to use image url
//source={require('image!k')}
source={{uri: 'http://news.xinhuanet.com/world/2015-05/09/127782089_14311512601821n.jpg'}}
I only get a red rect border.
When I use another js file, everything works well."Hello World" can show on iPad screen.
'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);
Make sure you are using a recent version of React Native. With React Native 0.4.4 following works:
Local image
<Image
style={styles.base}
source={require('image!tabnav_settings')}
/>
Also make sure you added the image you want to use to your image assets:
Remote Image
<Image
style={styles.base}
source={{uri: 'http://i.stack.imgur.com/DfkfD.png'}}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With