Need to make Image Bottom to corner: React Native

对着背影说爱祢 提交于 2019-12-02 10:59:15

问题


I want to make image rounded from bottom of it. Here is what I wanted to make:

I have tried to set borderRadius, but it will apply for the whole image not for bottom.

Here is my code:

<View
        style={{
          backgroundColor: ‘transparent’,
          justifyContent: ‘center’,
          alignItems: ‘center’,
          height: 159,
          width: '100%',
          borderBottomWidth: 70,
          borderBottomColor: ‘red’,
          borderBottomRightRadius: 800,
          borderBottomLeftRadius: 800,
        }}
      />

It will give output like this:

Which property do I need to set to make a perfect round on the bottom of view?


回答1:


you can add a png frame transparent with this shape on it

also you can check this it may help the-shapes-of-react-native


Update

here is how I managed do this by code

first you create this structure

render() {
  return(
    <View style={styles.container} >
      <View style={styles.background} >
        <Image style={styles.image} source={require('./image.jpeg')} />
      </View>
    </View>
  );
}

and then apply this style

const styles = {
  container: {
    alignSelf: 'center',
    marginTop: 100,
    width: 200,
    overflow: 'hidden', // for hide the not important parts from circle
    margin: 10,
    height: 100,
  },
  background: { // this shape is a circle 
    borderRadius: 400, // border borderRadius same as width and height
    width: 400,
    height: 400,
    marginLeft: -100, // reposition the circle inside parent view
    position: 'absolute',
    bottom: 0, // show the bottom part of circle
    overflow: 'hidden', // hide not important part of image
  },
  image: {
    height: 100, // same width and height for the container
    width: 200,
    position: 'absolute', // position it in circle
    bottom: 0, // position it in circle
    marginLeft: 100, // center it in main view same value as marginLeft for circle but positive
  }
}

and here is the results




回答2:


You can check my repository, if it helps you

https://github.com/paraswatts/React_Native_Custom_shape_image_view/tree/master

There is a catch I have squeezed the width of image and then scaled it on X-axis




回答3:


Using the approach mentioned by @Mohamed Khalil,

const styles = StyleSheet.create({
containerStyle: {
    alignSelf: 'center',
    width: window.width,
    overflow: 'hidden',
    height: window.width / 1.7
},
sliderContainerStyle: {
    borderRadius: window.width,
    width: window.width * 2,
    height: window.width * 2,
    marginLeft: -(window.width / 2),
    position: 'absolute',
    bottom: 0,
    overflow: 'hidden'
},
slider: {
    height: window.width / 1.7,
    width: window.width,
    position: 'absolute',
    bottom: 0,
    marginLeft: window.width / 2,
    backgroundColor: '#9DD6EB'
}});

Here is the result. I used Dimensions (const window = Dimensions.get('window');) here to make it more dynamic to different screen sizes.



来源:https://stackoverflow.com/questions/46220316/need-to-make-image-bottom-to-corner-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!