Border Radius is unexpectedly uneven - css

I have a view with an icon (from react-native-vector-icons) inside as following:
return (
<View style={styles.iconContainerStyle}>
<Icon name='menu' size={23} style={styles.iconStyle} />
</View>
);
The following is the styling for both the components:
const styles = {
iconContainerStyle: {
justifyContent: 'center',
alignItems: 'center',
height: 30,
width: 35,
borderRadius: 5,
backgroundColor: '#ffffff',
padding: 2
},
iconStyle: {
color: '#2279b4',
}
};
The weird part is that the border radius prop of 5 should give evenly rounded borders, but this is what I get:
Notice that on the right hand side, the borders are sharper then the left part!
I even tried with different borderRaduis values, its still the same concept.

The header you see is provided by react-native-router-flex for my scenes, I think this is also a factor as their styles are also applied on the hamburger button.
A work around (temporarily) is by supplying another parent view with he following style:
<View style={{ justifyContent: 'center', alignItems: 'center', height: 35, width: 40, }}>
The height and width need to be a value bigger then that of the iconContainer.

Please add border: 1px solid #f00; to your code to see if toggle icon is not hidden behind something.
If it looks fine, try to add seperate radius to each angle, Like:
border-top-left-radius: 5px;
border-top-right-radius: 5px;
and so on. Also, try to use border-radius styles with !important.

Related

React native layout - center a video component

I try to add a video element horizontally centered in react native.
But somehow the style cant be applied to the video tag itself but it is applied to a div around the video tag. The video itself seems to have a postion:absolute.
The template code:
<View style={styles.container}>
<Video
ref={video}
style={styles.video}/>
</View>
Here the styling:
container: {
flex: 1,
display: 'flex',
backgroundColor: '#25292e',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
video:{
flex: 1,
alignSelf: 'center',
border: '1px solid black',
}
I am a react (native) newcomer.
How can I achieve it, that the video is always horizontally centered?
And why are there always extra div's around the elements?

The style attribute for rendering iframe in React/Typescript JSX, is an object, but other attributes are strings. How to write the styles?

I'm trying to pass an iframe tag inside my JSX that is returned from the component. The allow="..." seems to work as a string, but style="...." gives a JSX error, expecting a mapping, not a string.
return(
<Rnd
style={style.casualGameContainer}
default={{
x: 10,
y: 10,
width: 810,
height: 610,
zIndex: 21,
}}
>
<iframe id="iframe" title={gameInfo.name} name={gameInfo.name} src={gameInfo.url}
allow="display-capture;camera;microphone;fullscreen;payment;"
referrerpolicy="" frameborder="0" width="100%" height="100%"
style={{zIndex:'21', border:'1px,solid,white'}}>
</iframe>
</Rnd>
);
const style = StyleSheet.create({
casualGameContainer: {
width: '100%',
height: '74.12%',
flexDirection: 'row',
zIndex: '200',
},
The above passes the zIndex (converting it to z-index: 21) but does not pass the border.
And the z-index has no effect in the iframe. (and the z-index isn't passed to the Rnd element either.
EDIT:
It turns out Rnd cannot accept a stylesheet. I had to change to an object:
const style = {
width: '100%',
height: '74.12%',
flexDirection: 'row',
zIndex: '21',
};
The issue here is actually just that the syntax you've provided for the border isn't valid CSS
If you were doing this in plain CSS, you wouldn't write
.some-element {
border: 1px,solid,white;
}
you would write
.some-element {
border: 1px solid white;
}
So, you should change your style property to:
style={{zIndex: '21', border: '1px solid white'}}

CSS border collapse with MUI tabs

In this picture #1 is the regular border which I need to have. #2 and #3 are double the sizes of the #1. In the #4 we can see it happens because both nearby elements have borders and those aren't collapsed.
In my React / MUI project I have added borderCollapse: "collapse". But still, the problem is there.
This is my code sandbox
What went wrong in my code?
Each item in the Tabs gets it's own border that's why it looks double for the elements between.
The closest solution with the less code I could find is to add negative margin-left in each item except the first one like the code below. Here is the working codesandbox
<Tabs
value={value}
onChange={handleChange}
centered
variant="fullWidth"
aria-label="basic tabs example"
sx={{
".MuiButtonBase-root": {
color: "white",
textTransform: "none",
borderCollapse: "collapse",
border: "1px solid #83858E",
fontWeight: "normal",
marginLeft: "-1px" // You add negative margin
},
"& :first-child": {
borderTopLeftRadius: "0.5rem",
borderBottomLeftRadius: "0.5rem",
margin: "0" // You remove the negative margin-left for the first element.
},
"& :last-child": {
borderTopRightRadius: "0.5rem",
borderBottomRightRadius: "0.5rem"
},
"& .MuiTabs-indicator": {
display: "none"
},
"& .MuiTab-root.Mui-selected": {
color: "black",
backgroundColor: "#ABA9FF",
border: "1px solid white"
}
}}
>

StyleSheet /CSS : Placing Components in React Native

I am working on a React Native App . The components are vertically center as I desire but are all aligned on the bottom and can't get them move up towards the top of the screen.
Please take a look at the layout screen (attached here).
How can I get them to move up top?
Please Note : The yellow color in the screen is to figure out how far the component's view stretches.
I could not figure out to adjust the 'yellow' view. The 'yellow' view is only suppose to consist the donut/menu button .
<View style={styles.container}>
<TouchableOpacity style={styles.drawerButton} onPress={() => this.props.navigation.openDrawer()} >
<Image
source={menu}
style={{width: 25, height: 25, marginLeft: 5}}
/>
</TouchableOpacity>
<TextInput style={styles.addText} placeholder="Add New Item"/>
<Button style = {styles.submitButton} title = "Add" />
<TouchableOpacity style = {styles.pictureButton} onPress = {this.setCameraWindow}>
<Text style={{fontSize:14}}> Take Picture </Text>
</TouchableOpacity>
{this.state.isCameraVisible ? this.takePicture() : null }
</View>
);
}
}
const styles = StyleSheet.create ({
container:{
flex:1,
flexDirection: 'column',
alignItems:'center',
flexGrow: 1,
justifyContent: 'center',
backgroundColor: 'blue'
},
drawerButton:{
flex:1,
flexDirection:'row',
alignSelf:'flex-start',
backgroundColor:'yellow'
},
menuButton: {
height:50,
flex:1,
flexDirection:'column',
alignSelf:'flex-start',
backgroundColor:'yellow',
},
addText:{
flex:1,
flexDirection:'column',
justifyContent:'center',
backgroundColor:'white',
borderBottomColor: 'black',
borderBottomWidth: 2,
alignSelf:'center',
maxHeight:50,
},
submitButton:{
justifyContent:'center'
},
pictureButton:{
backgroundColor:'white',
justifyContent: 'center',
},
});
Thank you
You have given flex:1 inside the style={styles.drawerButton}, thats why its taking up the entire space and other things are pushed to the end of the screen, please remove flex:1 from that, and also remove justifyContent: 'center' from container style. Then all the content will be moved to the top
These styles are what you need. Specifically:
overflow: hidden: Hides the yellow bit when the menu is collapsed.
position: absolute on the menu. This means the menu will appear in the same position regardless of the other content. Use top: 10px; left: 10px to control the actual positioning of the menu.
position: relative on the menu's parent (TouchableOpacity) element. This means the position: absolute of the menu will be relative to the parent element.
You may have to get rid of some of the other styles, at least temporarily, so you can see what is happening.

React Native - manipulate View to apply shadow to Image's BorderRadius?

Having some styling issues on React Native with Shadows.
I'd like to get a shadow on just the image, which has curved edges (not a square) with the borderradius I've given it. But if I apply a shadow on the parent View, it can't seem to 'follow the edges' of the Image. I'd like for the shadow to be around the curved edges of the Image, not around the square view.
Here is my code:
<View style={[styles.closedcontainer]}>
<Image source={{uri: props.food.url}}
style={styles.smallimage}
/>
</View>
And here is my styling:
const styles = StyleSheet.create({
closedcontainer: {
height: 100,
width: 100,
flexDirection: 'row',
flexWrap: 'wrap',
paddingLeft: 50,
paddingRight: 50,
paddingBottom: 0,
paddingTop: 0,
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff9f9',
shadowColor: 'black',
shadowOffset: {width: 2, height: 5},
shadowOpacity: .30,
shadowRadius: 5,
// overflow: 'hidden'
},
smallimage: {
height: 100,
width: 100,
borderRadius: 30,
borderColor: "#f97070",
borderWidth: 2.75,
margin: 10,
backgroundColor: 'white',
resizeMode: 'contain'
}
I thought perhaps adding overflow hidden to the parent View's styling (closedcontainer) would do it, but that gets hides the whole shadow altogether.
Any ideas? Thanks!
UPDATE: per suggestion, tried setting the borderRadius directly in the , unfortunately still no luck.
Try setting borderRadius directly as a prop on the image instead using it as a style.
<Image borderRadius={25}/>
Or similar

Resources