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:
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:
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
add a comment |
up vote
2
down vote
favorite
I want to make a "rounded bottom" component, without using a ImageBackground
, like this:
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:
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
add a comment |
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:
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:
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
I want to make a "rounded bottom" component, without using a ImageBackground
, like this:
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:
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
react-native border
edited Nov 8 at 7:04
JJJ
29k147591
29k147591
asked Nov 7 at 22:11
pistou
1,85521943
1,85521943
add a comment |
add a comment |
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,
},
});
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
add a comment |
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,
},
});
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
add a comment |
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,
},
});
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
add a comment |
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,
},
});
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,
},
});
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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