Make border-radius greater than half of height











up vote
2
down vote

favorite












I want to make a "rounded bottom" component, without using a ImageBackground, like this:
enter image description here



I tried to use a combination of <LinearGradient/>, but to simplify the code in this question, I used <View/> instead.



Here is my code:



import React from 'react'
import { Dimensions, StyleSheet, View } from 'react-native'

export default class App extends React.Component {
constructor(props) {
super(props)
}

render() {
return (
<View style={classes.container}>
<View style={classes.block} />
<View style={classes.roundedBlock} />
</View>
)
}
}

const classes = StyleSheet.create({
container: {
flex: 1,
marginTop: 30,
},
block: {
height: 135,
backgroundColor: 'red',
},
roundedBlock: {
height: 15,
backgroundColor: 'red',
width: Dimensions.get('window').width,
borderBottomLeftRadius: Dimensions.get('window').width / 2,
borderBottomRightRadius: Dimensions.get('window').width / 2,
}
})


This code is available for tests purpose on Expo Snack



Here is the result:



enter image description here



As you can see, the borderRadius is limited to 7.5px, which is half of the height of the block, instead of half of the width as demanded.



Is there a way to override this limit? If no, is there a way to achieve what I want?










share|improve this question




























    up vote
    2
    down vote

    favorite












    I want to make a "rounded bottom" component, without using a ImageBackground, like this:
    enter image description here



    I tried to use a combination of <LinearGradient/>, but to simplify the code in this question, I used <View/> instead.



    Here is my code:



    import React from 'react'
    import { Dimensions, StyleSheet, View } from 'react-native'

    export default class App extends React.Component {
    constructor(props) {
    super(props)
    }

    render() {
    return (
    <View style={classes.container}>
    <View style={classes.block} />
    <View style={classes.roundedBlock} />
    </View>
    )
    }
    }

    const classes = StyleSheet.create({
    container: {
    flex: 1,
    marginTop: 30,
    },
    block: {
    height: 135,
    backgroundColor: 'red',
    },
    roundedBlock: {
    height: 15,
    backgroundColor: 'red',
    width: Dimensions.get('window').width,
    borderBottomLeftRadius: Dimensions.get('window').width / 2,
    borderBottomRightRadius: Dimensions.get('window').width / 2,
    }
    })


    This code is available for tests purpose on Expo Snack



    Here is the result:



    enter image description here



    As you can see, the borderRadius is limited to 7.5px, which is half of the height of the block, instead of half of the width as demanded.



    Is there a way to override this limit? If no, is there a way to achieve what I want?










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I want to make a "rounded bottom" component, without using a ImageBackground, like this:
      enter image description here



      I tried to use a combination of <LinearGradient/>, but to simplify the code in this question, I used <View/> instead.



      Here is my code:



      import React from 'react'
      import { Dimensions, StyleSheet, View } from 'react-native'

      export default class App extends React.Component {
      constructor(props) {
      super(props)
      }

      render() {
      return (
      <View style={classes.container}>
      <View style={classes.block} />
      <View style={classes.roundedBlock} />
      </View>
      )
      }
      }

      const classes = StyleSheet.create({
      container: {
      flex: 1,
      marginTop: 30,
      },
      block: {
      height: 135,
      backgroundColor: 'red',
      },
      roundedBlock: {
      height: 15,
      backgroundColor: 'red',
      width: Dimensions.get('window').width,
      borderBottomLeftRadius: Dimensions.get('window').width / 2,
      borderBottomRightRadius: Dimensions.get('window').width / 2,
      }
      })


      This code is available for tests purpose on Expo Snack



      Here is the result:



      enter image description here



      As you can see, the borderRadius is limited to 7.5px, which is half of the height of the block, instead of half of the width as demanded.



      Is there a way to override this limit? If no, is there a way to achieve what I want?










      share|improve this question















      I want to make a "rounded bottom" component, without using a ImageBackground, like this:
      enter image description here



      I tried to use a combination of <LinearGradient/>, but to simplify the code in this question, I used <View/> instead.



      Here is my code:



      import React from 'react'
      import { Dimensions, StyleSheet, View } from 'react-native'

      export default class App extends React.Component {
      constructor(props) {
      super(props)
      }

      render() {
      return (
      <View style={classes.container}>
      <View style={classes.block} />
      <View style={classes.roundedBlock} />
      </View>
      )
      }
      }

      const classes = StyleSheet.create({
      container: {
      flex: 1,
      marginTop: 30,
      },
      block: {
      height: 135,
      backgroundColor: 'red',
      },
      roundedBlock: {
      height: 15,
      backgroundColor: 'red',
      width: Dimensions.get('window').width,
      borderBottomLeftRadius: Dimensions.get('window').width / 2,
      borderBottomRightRadius: Dimensions.get('window').width / 2,
      }
      })


      This code is available for tests purpose on Expo Snack



      Here is the result:



      enter image description here



      As you can see, the borderRadius is limited to 7.5px, which is half of the height of the block, instead of half of the width as demanded.



      Is there a way to override this limit? If no, is there a way to achieve what I want?







      react-native border






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 7:04









      JJJ

      29k147591




      29k147591










      asked Nov 7 at 22:11









      pistou

      1,85521943




      1,85521943
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can use ART from react-native to draw whatever you want to draw. Some unofficial docs https://github.com/react-native-china/react-native-ART-doc/blob/master/doc.md. Please check the Expo Snack or code below.



          import React from 'react';
          import { Dimensions, StyleSheet, View, ART } from 'react-native';

          const {
          Surface,
          Shape,
          Path,
          RadialGradient,
          Pattern,
          Transform,
          LinearGradient,
          } = ART;
          const width = Dimensions.get('window').width;
          export default class App extends React.Component {
          constructor(props) {
          super(props);
          }

          getPathRect = () => {
          const x = width;
          const y = 0;
          const radius = 1000;

          return ART.Path()
          .moveTo(x, y)
          .lineTo(x - width, y)
          .lineTo(x - width, y + width / 2)
          .lineTo(x, y + width / 2)
          .close();
          };

          getPathArc = () => {
          const x = width;
          const y = 0;
          const radius = 1000;
          return ART.Path()
          .moveTo(x, y + width / 2)
          .arc(-x, 0, radius, radius)
          .close();
          };

          gradient = () => {
          return new LinearGradient(
          {
          '.01': 'blue', // blue in 1% position
          '1': 'red', // opacity white in 100% position
          },
          '0',
          '0',
          width,
          '0'
          );
          };

          render() {
          return (
          <View style={classes.container}>
          <Surface width={width} height={width}>
          <Shape
          d={this.getPathRect()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          <Shape
          d={this.getPathArc()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          </Surface>
          </View>
          );
          }
          }

          const classes = StyleSheet.create({
          container: {
          flex: 1,
          marginTop: 30,
          },
          });





          share|improve this answer



















          • 1




            @pistou just updated my answer to add gradient as fill color.
            – Dmitri Portenko
            Nov 8 at 10:32






          • 1




            I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
            – pistou
            Nov 8 at 10:40











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198644%2fmake-border-radius-greater-than-half-of-height%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You can use ART from react-native to draw whatever you want to draw. Some unofficial docs https://github.com/react-native-china/react-native-ART-doc/blob/master/doc.md. Please check the Expo Snack or code below.



          import React from 'react';
          import { Dimensions, StyleSheet, View, ART } from 'react-native';

          const {
          Surface,
          Shape,
          Path,
          RadialGradient,
          Pattern,
          Transform,
          LinearGradient,
          } = ART;
          const width = Dimensions.get('window').width;
          export default class App extends React.Component {
          constructor(props) {
          super(props);
          }

          getPathRect = () => {
          const x = width;
          const y = 0;
          const radius = 1000;

          return ART.Path()
          .moveTo(x, y)
          .lineTo(x - width, y)
          .lineTo(x - width, y + width / 2)
          .lineTo(x, y + width / 2)
          .close();
          };

          getPathArc = () => {
          const x = width;
          const y = 0;
          const radius = 1000;
          return ART.Path()
          .moveTo(x, y + width / 2)
          .arc(-x, 0, radius, radius)
          .close();
          };

          gradient = () => {
          return new LinearGradient(
          {
          '.01': 'blue', // blue in 1% position
          '1': 'red', // opacity white in 100% position
          },
          '0',
          '0',
          width,
          '0'
          );
          };

          render() {
          return (
          <View style={classes.container}>
          <Surface width={width} height={width}>
          <Shape
          d={this.getPathRect()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          <Shape
          d={this.getPathArc()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          </Surface>
          </View>
          );
          }
          }

          const classes = StyleSheet.create({
          container: {
          flex: 1,
          marginTop: 30,
          },
          });





          share|improve this answer



















          • 1




            @pistou just updated my answer to add gradient as fill color.
            – Dmitri Portenko
            Nov 8 at 10:32






          • 1




            I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
            – pistou
            Nov 8 at 10:40















          up vote
          1
          down vote



          accepted










          You can use ART from react-native to draw whatever you want to draw. Some unofficial docs https://github.com/react-native-china/react-native-ART-doc/blob/master/doc.md. Please check the Expo Snack or code below.



          import React from 'react';
          import { Dimensions, StyleSheet, View, ART } from 'react-native';

          const {
          Surface,
          Shape,
          Path,
          RadialGradient,
          Pattern,
          Transform,
          LinearGradient,
          } = ART;
          const width = Dimensions.get('window').width;
          export default class App extends React.Component {
          constructor(props) {
          super(props);
          }

          getPathRect = () => {
          const x = width;
          const y = 0;
          const radius = 1000;

          return ART.Path()
          .moveTo(x, y)
          .lineTo(x - width, y)
          .lineTo(x - width, y + width / 2)
          .lineTo(x, y + width / 2)
          .close();
          };

          getPathArc = () => {
          const x = width;
          const y = 0;
          const radius = 1000;
          return ART.Path()
          .moveTo(x, y + width / 2)
          .arc(-x, 0, radius, radius)
          .close();
          };

          gradient = () => {
          return new LinearGradient(
          {
          '.01': 'blue', // blue in 1% position
          '1': 'red', // opacity white in 100% position
          },
          '0',
          '0',
          width,
          '0'
          );
          };

          render() {
          return (
          <View style={classes.container}>
          <Surface width={width} height={width}>
          <Shape
          d={this.getPathRect()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          <Shape
          d={this.getPathArc()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          </Surface>
          </View>
          );
          }
          }

          const classes = StyleSheet.create({
          container: {
          flex: 1,
          marginTop: 30,
          },
          });





          share|improve this answer



















          • 1




            @pistou just updated my answer to add gradient as fill color.
            – Dmitri Portenko
            Nov 8 at 10:32






          • 1




            I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
            – pistou
            Nov 8 at 10:40













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You can use ART from react-native to draw whatever you want to draw. Some unofficial docs https://github.com/react-native-china/react-native-ART-doc/blob/master/doc.md. Please check the Expo Snack or code below.



          import React from 'react';
          import { Dimensions, StyleSheet, View, ART } from 'react-native';

          const {
          Surface,
          Shape,
          Path,
          RadialGradient,
          Pattern,
          Transform,
          LinearGradient,
          } = ART;
          const width = Dimensions.get('window').width;
          export default class App extends React.Component {
          constructor(props) {
          super(props);
          }

          getPathRect = () => {
          const x = width;
          const y = 0;
          const radius = 1000;

          return ART.Path()
          .moveTo(x, y)
          .lineTo(x - width, y)
          .lineTo(x - width, y + width / 2)
          .lineTo(x, y + width / 2)
          .close();
          };

          getPathArc = () => {
          const x = width;
          const y = 0;
          const radius = 1000;
          return ART.Path()
          .moveTo(x, y + width / 2)
          .arc(-x, 0, radius, radius)
          .close();
          };

          gradient = () => {
          return new LinearGradient(
          {
          '.01': 'blue', // blue in 1% position
          '1': 'red', // opacity white in 100% position
          },
          '0',
          '0',
          width,
          '0'
          );
          };

          render() {
          return (
          <View style={classes.container}>
          <Surface width={width} height={width}>
          <Shape
          d={this.getPathRect()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          <Shape
          d={this.getPathArc()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          </Surface>
          </View>
          );
          }
          }

          const classes = StyleSheet.create({
          container: {
          flex: 1,
          marginTop: 30,
          },
          });





          share|improve this answer














          You can use ART from react-native to draw whatever you want to draw. Some unofficial docs https://github.com/react-native-china/react-native-ART-doc/blob/master/doc.md. Please check the Expo Snack or code below.



          import React from 'react';
          import { Dimensions, StyleSheet, View, ART } from 'react-native';

          const {
          Surface,
          Shape,
          Path,
          RadialGradient,
          Pattern,
          Transform,
          LinearGradient,
          } = ART;
          const width = Dimensions.get('window').width;
          export default class App extends React.Component {
          constructor(props) {
          super(props);
          }

          getPathRect = () => {
          const x = width;
          const y = 0;
          const radius = 1000;

          return ART.Path()
          .moveTo(x, y)
          .lineTo(x - width, y)
          .lineTo(x - width, y + width / 2)
          .lineTo(x, y + width / 2)
          .close();
          };

          getPathArc = () => {
          const x = width;
          const y = 0;
          const radius = 1000;
          return ART.Path()
          .moveTo(x, y + width / 2)
          .arc(-x, 0, radius, radius)
          .close();
          };

          gradient = () => {
          return new LinearGradient(
          {
          '.01': 'blue', // blue in 1% position
          '1': 'red', // opacity white in 100% position
          },
          '0',
          '0',
          width,
          '0'
          );
          };

          render() {
          return (
          <View style={classes.container}>
          <Surface width={width} height={width}>
          <Shape
          d={this.getPathRect()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          <Shape
          d={this.getPathArc()}
          fill={this.gradient()}
          // stroke="red"
          strokeWidth="1"
          strokeCap="butt"
          strokeJoin="bevel"
          />
          </Surface>
          </View>
          );
          }
          }

          const classes = StyleSheet.create({
          container: {
          flex: 1,
          marginTop: 30,
          },
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 8 at 10:27

























          answered Nov 8 at 0:05









          Dmitri Portenko

          598420




          598420








          • 1




            @pistou just updated my answer to add gradient as fill color.
            – Dmitri Portenko
            Nov 8 at 10:32






          • 1




            I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
            – pistou
            Nov 8 at 10:40














          • 1




            @pistou just updated my answer to add gradient as fill color.
            – Dmitri Portenko
            Nov 8 at 10:32






          • 1




            I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
            – pistou
            Nov 8 at 10:40








          1




          1




          @pistou just updated my answer to add gradient as fill color.
          – Dmitri Portenko
          Nov 8 at 10:32




          @pistou just updated my answer to add gradient as fill color.
          – Dmitri Portenko
          Nov 8 at 10:32




          1




          1




          I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
          – pistou
          Nov 8 at 10:40




          I was doing the same on my side, I figured out the params for the gradient, and I modified the Snack to fit my needs.
          – pistou
          Nov 8 at 10:40


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198644%2fmake-border-radius-greater-than-half-of-height%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini