Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  142] [ 6]  / answers: 1 / hits: 41858  / 9 Years ago, fri, march 27, 2015, 12:00:00

Just getting started with React-Native and I'm having some trouble requiring a static image.


Here's the very-basic code I have so far:


'use strict';

var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
Image,
View,
} = React;

var buzz = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Image source={require('image!bg')} style={styles.bg}>
<Text style={styles.welcome}>
Welcome to Buzz! iOS interface to
</Text>
<Text style={styles.welcomeHeader}>Charityware</Text>
</Image>
</View>
);
}
});

var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'transparent'
},
welcomeHeader: {
fontWeight: '600',
fontFamily: 'Helvetica',
color: '#fff',
fontSize: 50,
alignSelf: 'center'
},
bg: {
width: 400,
height: 300,
alignSelf: 'auto',

},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
},
});

AppRegistry.registerComponent('buzz', () => buzz);

The main trouble area is:


    <Image source={require('image!bg')}  style={styles.bg}>
<Text style={styles.welcome}>
Welcome to Buzz! iOS interface to
</Text>
<Text style={styles.welcomeHeader}>Charityware</Text>
</Image>

When packaging my app and running it, I get a render error:
error


I understand that you need to add images in xcode as an image set in order for the require call to find the image and have added an image set to that end:
bg


...But to no avail. Anyone have any thoughts? I've read the docs and seem to be doing this in the prescribed way. Thanks!


More From » ios

 Answers
24

Since React Native release 0.14 the handling of images has been normalized for iOS and Android and is now different. I could not find any documentation except for this very clear commit note on Github: Document new asset system.



There's only a screenshot of the proposed documentation:
enter



Update:
There is a link now for the real documentation:
https://facebook.github.io/react-native/docs/images.html


[#67280] Thursday, March 26, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byrondonavanc

Total Points: 675
Total Questions: 107
Total Answers: 105

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
byrondonavanc questions
;