How to overlap images in react-native
I review your code and make some changes to get your expected output. The updated code is:-
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var SampleApp = React.createClass({
render: function() {
return (
<View style={styles.container}>
<View style={styles.avatar}>
<View style={styles.badge} />
</View>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
},
avatar: {
backgroundColor: 'black',
width: 60,
height: 60,
},
badge: {
backgroundColor: 'red',
width: 20,
height: 20,
left: 20,
top: 20,
},
});
AppRegistry.registerComponent('SampleApp', () => SampleApp);
See the change in above code snippet. Output screenshot link:- https://drive.google.com/file/d/0B_8x_Jy7Ac9bbDh1eHhfelJpSmc/view?usp=sharing
Whenever you want to override any react component simply put that component in between start and close of another component. For example:-
If you want to overlap one image on another then use tags like
<Image source={require('image!firstimage')} style={..}>
<Image source={require('image!secondimage')} style={..}>
</Image>
Nesting Image
components doesn't work anymore. What you could use is ImageBackground
instead or absolute positioning.
As doc says you can code your own specific component by checking the source code of ImageBackground
https://github.com/facebook/react-native/blob/master/Libraries/Image/ImageBackground.js