【问题标题】:Curved bottom on View视图上的弧形底部
【发布时间】:2018-02-24 23:11:22
【问题描述】:

如何在 react-native 中将弯曲的底部添加到视图中? See curved example

我试过像这样添加第二个视图:

标题底部:{ 宽度:宽度/2, 高度:宽度/2, 背景颜色:'红色', 位置:'绝对', 底部:-35, 左:宽度 / 4 - 15, 边界半径:宽度/ 4, 转变: [ {scaleX: 2}, {scaleY:0.25} ] },

我已经能够超越,但在同一个视图中有一个不太糟糕的解决方案,而不是在第二个视图中的示例。

【问题讨论】:

  • 不是一个答案,但对于未来的读者来说,这是一个与this one 非常相似的问题,关于Image 组件。
  • 查看我在这个帖子上的回答,如果对你有帮助,stackoverflow.com/questions/46220316/…
  • 感谢您的想法!我已经审查了您的建议,并将尽快实施。我希望通过borderBottomRadius 或其他方式获得更漂亮的解决方案,但这还不可能。还是谢谢
  • 你有没有为这个@MvdL找到任何解决方案?

标签: react-native


【解决方案1】:

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

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】:

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

    <Circle
      cx={screenWidth / 2}
      cy={`-${898 - headerHeight + 2}`}
      r="898.5"
      fill="#EFF2F3"
      stroke="#C5CACD"
      strokeWidth="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'
          }
      })
      

      【讨论】:

        【解决方案4】:

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

        class Home extends Component {
            render() {
                return (
                    <View style={styles.oval} />
                )
            }
        }
        
        const styles= StyleSheet.create({
            oval: {
                height: 100,
                borderBottomLeftRadius: 50,
                borderBottomRightRadius: 50,
                backgroundColor: 'red'
            },
        });
        

        【讨论】:

        • 感谢您的示例!但是,我正在寻找一个完整的曲线底部,而不仅仅是角落
        • 任何解决方案@MvdL?
        • @AbhishekDS 是的!我最终用 react-native-svg 制作了它。 ``` -${898 - headerHeight + 2}} r="898.5" fill="#EFF2F3" stroke="#C5CACD" strokeWidth="2" /> ```
        猜你喜欢
        • 1970-01-01
        • 2020-10-23
        • 2021-08-12
        • 2019-05-23
        • 2018-08-21
        • 1970-01-01
        • 1970-01-01
        • 2019-12-25
        • 2018-09-30
        相关资源
        最近更新 更多