Add rounded edges to React radial chart segments - reactjs

I have a react based radial progress chart . Here is the codesandbox
What I'm trying to do is add some roundness to the segments themselves so that they have rounded edges.
I tried adding in borderRadius: "10" but that didn't cut in. Any suggestions?
<RadialSeparators
count={20}
style={{
background: "#fff",
width: "2px",
borderRadius: "10",
// This needs to be equal to props.strokeWidth
height: `${10}%`
}}
/>

Related

React Native image: why does parent view stay same height as 'cover' when set to 'contain'?

I have the following image in my React Native app
I want to have this image inside a parent element with no space above or below it, and I want the image to not overshoot the left or right sides of the screen
When I have the code like this
<View style={{
marginTop: 100,
borderWidth: 2,
borderColor: 'red'
}}>
<Image
style={{
width: '100%'
}}
source={require('#images/swoosh-02.png')}
/>
</View>
I get this, because default for resizeMode is cover
When I change it to this (adding resizeMode='contain')
<View style={{
marginTop: 100,
borderWidth: 2,
borderColor: 'red'
}}>
<Image
style={{
width: '100%'
}}
resizeMode='contain'
source={require('#images/swoosh-02.png')}
/>
</View>
the image gets successfully contained horizontally, but the height of the parent element remains the same as it was when resizeMode was cover.
How can I get it so that the parent element shrinks vertically to contain only the image and not have that extra top/bottom padding?
De diference between contain and cover is :
resizeMode='contain' = Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
resizeMode='cover' = Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
Maybe you should try to apply height in your View.
Read this article, should help you.

React Native: Why is image stretching vertically to fill container and how to prevent it?

In my React Native app, I have a red box of height 300 that I want to center vertically, and an image that I want to sit inside and at the top of this red box. Here is my code so far:
import React, { Component } from 'react';
import { View, Image} from 'react-native';
export default class Login extends Component {
render() {
return (
<View style={{
flex: 1,
justifyContent: "center",
alignItems: "center"
}}>
<View
style={{
borderWidth: 3,
borderColor: 'red',
width: "100%",
height: 300
}}
>
<Image
source={require('../../images/swoord-top.png')}
style={{
width: "100%",
height: "100%",
resizeMode: "contain",
borderWidth: 3
}}
>
</Image>
</View>
</View>
);
}
}
Here's what this looks like:
The red box is the outer box I mentioned, and the black box is just the border of the Image. The problem is that this black box (ie the Image) expands to fill the red box vertically, and the image is vertically centered inside this black box, so it's vertically centered inside the red box, as opposed to at the flex-start position that I want it at. I've tried adding justifyContent: flex-start and flexShrink: 1 to the Image and neither has made a difference.
Does anyone know how I can approach this?
NOTE:
If I remove the height: 100% on the Image, I get this:
UPDATE:
To clarify, this is what I'd like it to look like. I've removed the black border here. I moved it up to where I want it by adding top: -95, but this won't work in general because the value would be different for different devices:
try doing like this
<Image
source={require('../../images/swoord-top.png')}
style={{
width: "100%",
borderWidth: 3
}}
resizeMode={"contain"}
/>
There is a difference between Image (the view) and the content of that image. On your screenshot, the image view has the black border and its content is sitting inside of it. Because they have different aspect ratios, there is going to be either a blank space or cut-off on the content. You can't adjust position of the content as it's not laid out on flex basis. Image view is just a window that then renders image content. There is no property to tell Image where to align that content
Your problem comes from the fact that screen width differs, and aspect ratio of your container also differs (variable width but constant 300 height). What you need to do is
measure container width
determine proper aspect ratio for the image based on image resource width and height
set your image width to 100% and its height according to received aspect ratio
here, my image dimensions are 1005 * 219:
const Test = () => {
const [width, setWidth] = useState(0);
return (
<View>
<View
onLayout={e => setWidth(e.nativeEvent.layout.width)}
style={{ width: '100%', height: 300, borderWidth: 1 }}>
<Image
style={{
width: '100%',
height: (width / 1005) * 219,
borderWidth: 1,
borderColor: 'red',
}}
source={require('...')}
/>
</View>
</View>
);
};

How to display specific part of image in square

I have problem with Image component in react native. I would like to display specific part of image in some square. F.e:
Let's say, I have image in resolution: 1280x720
private someImage = require('../Assets/someImage.jpg');
I would like to display this image in square component (with constant size)
<View style={{width: 64, height: 64}}>
<Image source={this.someImage}
style={{position: 'absolute', top: 0, left: 0 }} />
</View>
Here comes the first problem: Image goes beyond the square. How can I show only part of my image (but with original resolution).
The second question is:
Is there a way to showing specific fragment of my image? That's men if I set top: -64, left: -64 I would like to see original image move about 64 pixels diagonally.
Jroslaw. this may helpful for you.
const someImage = require('../Assets/someImage.jpg');
class ImageClip extends Components {
...
render() {
return (
...
<View style={{ width: 64, height: 64, overflow: 'hidden' }}> // width and height of image you want display.
<Image
source={someImage}
style={{
top: 24,
left: 32,
}} //position of image you want display.
/>
</View>
...
);
}
}
To show your image with full resolution but with only the section you choose, you will need to display the image within a fixed sized container. This image will also need to be a background-image in the style attribute.
<View style={{background-image: this.someImage, background-position-x: -64px, background-position-y: -64px}}>
Giving " overflow:'hidden' " to the parent view also works for me.
Resize-mode:contain will NOT work, as it will resize your image to fit entirely within the 64x64 container, not what you want in this case.
<View style={{width: 64, height: 64, overflow: 'hidden'}}>
<Image
source={{uri: 'https://picsum.photos/200/300'}}
style={{
height: 200,
width: 200,
top: -50,
left: -70,
}}
/>
</View>

How to change the background color of an ant.design InputNumber?

<InputNumber
min={13}
max={125}
defaultValue={this.props.defaultValue}
style={{
width: this.props.width,
borderColor: this.props.colorTheme.text6Color, <= Working
backgroundColor: this.props.colorTheme.text7Color, <= edits the rectangle behind the white rectangle with circle edges
background: this.props.colorTheme.text7Color, <= Not working
color: this.props.colorTheme.keyText3Color <= Not working
}}
/>
How can I style the back of the InputNumber?
Are you using plain CSS?
If you just want to change the color, you may try:
backgroundColor: this.props.colorTheme.text7Color
Use
style={{backgroundColor: this.props.colorTheme.text7Color}}

How do I position a button at the bottom always? This will be rendered from a component whose parent is a scrollview

How do I position a button at the bottom always? This will be rendered from a component whose parent is a scrollview. When I use abosolute position, positioning works, but when I scroll the view the button scrolls as well.
positionInBottom {
position: 'relative',
width: 50,
height: 50,
top: 160 - 26,
left: Dimensions.get('window').width - 70,
backgroundColor: 'red,
zIndex: 100,
}
Here is my componet structure: It's a sudo code.
<Page>
<ScrollView>
<Items items={this.items}/>
</ScrollView>
</Page>
<Items>
{items.map((item) => {
<Text>{item.name}</Text>
})
}
<Button stype={styles.positionInBottom} name="stay in the bottom" label="stay in the bottom"/>
</Items>
The following the documentation from react native. What does the bolded lines exactly means? I don't understand it.
position ReactPropTypes.oneOf([ 'absolute', 'relative' ])
position in React Native is similar to regular CSS, but everything is set to relative by default, so absolute positioning is always just relative to the parent.
If you want to position a child using specific numbers of logical pixels relative to its parent, set the child to have absolute position.
If you want to position a child relative to something that is not its parent, just don't use styles for that. Use the component tree.
See https://github.com/facebook/css-layout for more details on how position differs between React Native and CSS.
positionInBottom {
position: 'absolute',
width: 50,
height: 50,
bottom: 0,
left: Dimensions.get('window').width - 70,
backgroundColor: 'red',
zIndex: 100,
}

Resources