视图上的弯曲底部

时间:2017-09-15 17:40:15

标签: react-native

如何在反应原生的视图中添加弯曲的底部? See curved example

我尝试添加第二个视图:

headerBottom:{     宽度:宽度/ 2,     高度:宽度/ 2,     backgroundColor:' red',     位置:'绝对',     底部:-35,     左:宽度/ 4 - 15,     borderRadius:width / 4,     转变: [       {scaleX:2},       {scaleY:0.25}     ]   },

我已经能够在同一个视图中获得更高的解决方案,而不是在第二个视图中的示例中。

4 个答案:

答案 0 :(得分:4)

我最终使用了react-native-svg。:

<Circle
  cx={screenWidth / 2}
  cy={`-${898 - headerHeight + 2}`}
  r="898.5"
  fill="#EFF2F3"
  stroke="#C5CACD"
  strokeWidth="2"
/>

答案 1 :(得分:3)

这是结果。我在这里使用了Dimensions(const window = Dimensions.get('window');),以使其在不同的屏幕尺寸下更加动态。

enter image description here

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'
}});


render() {
  return(
    <View style={styles.containerStyle} >
      <View style={styles.sliderContainerStyle} >
        <Slider/>
      </View>
    </View>
  );
}

答案 2 :(得分:3)

我不知道这是否是正确的方法。但是,这对我有用,希望对您有所帮助。

<View style={styles.parent}>
     <View style={styles.child}>
         <Text>Hello World</Text>
     </View>
</View>

将代码插入子视图

const styles = StyleSheet.create({
    parent : {
        height : '80%',
        width : '100%',
        transform : [ { scaleX : 2 } ],
        borderBottomStartRadius : 200,
        borderBottomEndRadius : 200,
        overflow : 'hidden',
    },
    child : {
        flex : 1,
        transform : [ { scaleX : 0.5 } ],

        backgroundColor : 'yellow',
        alignItems : 'center',
        justifyContent : 'center'
    }
})

enter image description here

答案 3 :(得分:1)

我使用边框底部半径。这是工作。

enter image description here

class Home extends Component {
    render() {
        return (
            <View style={styles.oval} />
        )
    }
}

const styles= StyleSheet.create({
    oval: {
        height: 100,
        borderBottomLeftRadius: 50,
        borderBottomRightRadius: 50,
        backgroundColor: 'red'
    },
});