CSS Triangles in React Native

前端 未结 4 1880
Happy的楠姐
Happy的楠姐 2021-02-12 14:28

\"triangle\"

I\'m working on an app that uses triangles that overlay other containers/divs. Had that solved with CS

4条回答
  •  自闭症患者
    2021-02-12 14:53

    It is still possible to draw triangles in React Native using the CSS trick. I wrote a class to encapsulate this: https://github.com/Jpoliachik/react-native-triangle

    If you'd like to write it yourself, I used this tool: http://apps.eky.hk/css-triangle-generator/ to generate the triangle I wanted and modify the styles to React Native syntax.

    For example, an Isosceles triangle 90x90 pointing up in CSS reads:

    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 45px 90px 45px;
    border-color: transparent transparent #007bff transparent;
    

    But in React Native the styles would be:

    triangle: {
         width: 0,
         height: 0,
         backgroundColor: 'transparent',
         borderStyle: 'solid',
         borderTopWidth: 0,
         borderRightWidth: 45,
         borderBottomWidth: 90,
         borderLeftWidth: 45,
         borderTopColor: 'transparent',
         borderRightColor: 'transparent',
         borderBottomColor: 'red',
         borderLeftColor: 'transparent',
       },
    

提交回复
热议问题