Amit Malakar
Amit Malakar

Reputation: 608

React Native - Image Semi Circle (using CSS)

I have a circular image, which I need to show in Semi Circle using React Native like as shown in attached file. Please help with the CSS.

enter image description here

Upvotes: 4

Views: 16094

Answers (2)

alokkumardubey
alokkumardubey

Reputation: 104

Here is the solution I found for both left and right position of image:

renderLeftRightImage (item, index) {
    var imagePath = item.image?(Strings.BASE_IMAGE_URL+item.image[0].image):'https://placeimg.com/640/480/people';        

    if(item.position == 'left'){
        return(
            <View style={{overflow: 'hidden', width : 105, height:210, position : 'absolute', left:80,  bottom:62, borderTopLeftRadius:150, borderBottomLeftRadius:150, backgroundColor:'transparent'}}>
                <Image style={{width : 210, height:210}} source={{uri:imagePath}}/>
            </View>
        )
    }
    else if(item.position == 'right'){
        return(
            <View style={{overflow: 'hidden', width : 105, height:210, position : 'absolute', right:80,  bottom:62, borderTopRightRadius:150, borderBottomRightRadius:150, backgroundColor:'transparent'}}>
                <Image style={{width : 210, height:210, position:'absolute', right:0}} source={{uri:imagePath}}/>
            </View>
        )
    }
    else{
        return null;
    }
}

Upvotes: 4

bennygenel
bennygenel

Reputation: 24680

You can use overflow CSS prop with the combination of border-radius

Sample

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.imageContainer}>
          <View style={styles.imageWrapper}>
            <Image source={{uri: 'https://dummyimage.com/500x500/000/fff.png'}} style={styles.image} />
          </View>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  imageContainer: {
    alignItems: 'center',
    backgroundColor: 'yellow'
  },
  imageWrapper: {
    width: 125, // half of the image width
    height: 250,
    backgroundColor: 'transparent',
    overflow: 'hidden'
  },
  image: {
    width: 250,
    height: 250,
    borderRadius: 125, // half of the image width
    backgroundColor: 'transparent'
  }
});

Upvotes: 0

Related Questions