I'm working on a React Native app that has a user avatar component with an overlap effect:
I was able to get it working on iOS since it allows negative margins, but when you use negative margins on Android, it clips the last image like this:
Here are the styles I'm using:
avatarContainer: {
borderRadius: 20,
width: 40,
height: 40,
marginRight: -11
},
avatar: {
borderRadius: 20,
width: 40,
height: 40
},
avatarContainer is the white circle behind the image and avatar is the image itself.
What is the best approach that works on both platforms to accomplish the desired styling?
Negative margin is not supported on Android. Use absolute layout.
According to the article, you can use react-native-view'overflow library (a bridging header written to support the overflow in react-native android. All you need to do is wrap the overflowcomponent in the <ViewOverflow> . Hope this helps! Save this answer.
React Native provide lineHeight style props to make vertical space between text. lineHeight default value is 0 use if developer not defined lineHeight for text.
I've tried with pretty much your setup + flexbox and everything seems to work ok.
class App extends React.Component {
render() {
const { overlapContainer, avatarContainer, avatar} = styles;
return (
<View style={overlapContainer}>
<View style={avatarContainer}>
<Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-3.jpg' }} />
</View>
<View style={avatarContainer}>
<Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-7.jpg' }} />
</View>
<View style={avatarContainer}>
<Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-3.jpg' }} />
</View>
<View style={avatarContainer}>
<Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-7.jpg' }} />
</View>
</View>
);
}
}
const styles = {
overlapContainer: {
flexDirection: 'row-reverse',
justifyContent: 'flex-end',
marginTop: 50,
marginRight: 50
},
avatarContainer: {
borderRadius: 33,
height: 66,
width: 66,
marginLeft: -15,
borderStyle: 'solid',
borderWidth: 3,
borderColor: 'white'
},
avatar: {
borderRadius: 30,
height: 60,
width: 60
}
}
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