My hamburgers are not aligning on the screen
I have visited different style methods like alignItems but still no results. concerning margins positioning I cannot go further left separating each line (all 3 of them) by about 2 px each.
the main problem is the horizontal alignment of each line.
Can someone help, please?
import React from 'react';
import {AppRegistry, StyleSheet, View} from "react-native" ;
export default class MenuButton extends React.Component {
render() {
return(
<View style={menuIcon.mainLine}>
<View style={menuIcon.line2}>
<View style={menuIcon.line3}>
</View>
</View>
</View>
)
}
}
const menuIcon = StyleSheet.create({
mainLine: {
flex: 1,
backgroundColor : 'rgba(255, 255, 255, 1)',
top : 4,
height : 6.5,
width : 35,
position : 'absolute',
marginTop : 40,
marginLeft : 25,
alignItems : "stretch",
left : 0,
right : 0,
borderRadius : 20,
borderStyle : 'solid',
borderWidth : 1,
borderColor : 'rgba(205, 205, 205, 1)'
},
line2: {
flex: 1,
backgroundColor : 'rgba(255, 255, 255, 1)',
top : 7,
height : 6.5,
width : 35,
position : 'absolute',
marginTop : 0,
marginLeft : 0,
left : 0,
right : 0,
borderRadius : 20,
borderStyle : 'solid',
borderWidth : 1,
borderColor : 'rgba(205, 205, 205, 1)'
},
line3: {
flex: 1,
backgroundColor : 'rgba(255, 255, 255, 1)',
top : 7,
height : 6.5,
width : 35,
position : 'absolute',
marginTop : 0,
marginLeft : 0,
left : 0,
right : 0,
borderRadius : 20,
borderStyle : 'solid',
borderWidth : 1,
borderColor : 'rgba(205, 205, 205, 1)'
}
})
AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
i recommend using react-native-vector-icons for that.
but if you want to implement it yourself do this changes in your render function
render() {
return(
<View>
<View style={menuIcon.mainLine}></View>
<View style={menuIcon.line2}></View>
<View style={menuIcon.line3}></View>
</View>
)
}
usually we dont write hamburger code by our self .. or any other buttons icons.
We use icons or images inside view and apply onPress on view itself
with react-native we use react-native-vector-icons library. Installation basic usage guide here
https://www.npmjs.com/package/react-native-vector-icons
Related
I'm in need of applying a box shadow to one of my buttons in my react native application but box shadow property is not supported in android. So i'm trying to create a shadow view from LinearGradient and place the button at center of that view. Something like this
<LinearGradient
colors={['transparent', backgroundColor]}
start={{ x: 0.5, y: 0.5 }}
end={{ x: 1, y: 1 }}
style={{
width: '100%',
padding: 5,
height: 60,
justifyContent: 'center',
alignItems: 'flex-start',
marginTop: 0,
borderRadius: 2,
backgroundColor: 'transparent',
zIndex: 2,
bottom: 0,
}}>
<Pressable
onPress={onPress}
disabled={disabled}
style={({ pressed }) => [
{
borderWidth: state === 'primary_link' ? 0 : pressed ? 4 : borderWidth,
},
styles.background,
]}>
<ButtonTitle />
</Pressable>
</LinearGradient>
I tried changing the start and end values but could not get it to start from the center. Is there a way to do this using LinearGradient? I'm trying to get something like this
As the name implies, LinearGradient is for linear gradients only. What you described is a radial gradient. See this issue: https://github.com/react-native-linear-gradient/react-native-linear-gradient/issues/29
You may have box shadows as described here: Creating a UI with box shadow in react native
boxWithShadow: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 5
}
Styled components has a compose utility to combine multiple Styled System functions in a single component. I want to compose the lineHeight and fontSize together based on the default array.
Instead of doing:
<Heading type="h1"
fontSize={[ 1, 2, 3 ]}
lineHeight={[1 , 2, 3 ]}
color={theme.colors.heading.tinted}
>
I want to achieve only a font prop that has the fontSize and lineHeight combined.
<Heading type="h1"
font={[ 1, 2, 3 ]}
color={theme.colors.heading.tinted}
>
Heading.jsx
const Element = styled('div')(
space,
color,
compose(
fontSize,
lineHeight
)
);
theme.js
const theme = {
fontSizes: [11, 13, 16, 23, 29, 37, 47, 76, 97],
lineHeights: ['12px', '12px', '12px', '32px', '32px', '40px', '48px', '56px', '72px', '80px', '104px']
}
I have created a codesandbox example with your requirements:
Whole file is here:
https://codesandbox.io/s/styled-component-basic-j3zpx
<Title font={[50, 45]}>
This is a heading includes first array index for font size and second array for line height.
</Title>
styled css:
export const Title = styled.h1`
color: red;
margin: 0;
border: 1px solid black;
${props =>
props.font &&
css`
font-size: ${props => (props.font[0] ? `${props.font[0]}px` : "20px")};
line-height: ${props => (props.font[1] ? `${props.font[1]}px` : "30px")};
`}
`;
I am trying to test the border on an image using testcafe using getStyleProperty('border') and it always returns undefined. Other properties like box-shadow work fine.
HTML:
<img id="imgEdit" class="img-editable" [src]="imageUrl" style="border: 12px
solid rgb(0, 0, 0);" alt="editable image" />
const image = Selector('#imgEdit');
const imageBorder = await image.getStyleProperty('border');
imageBorder is always undefined.
border in CSS is considered a Shorthand property. This is the reason why you cannot find the border property.
If you console.log(image.style), you will see the actual border* CSS properties that represent the style="border: 12px
solid rgb(0, 0, 0);" in your HTML.
'border-bottom-color': 'rgb(0, 0, 0)',
'border-bottom-left-radius': '0px',
'border-bottom-right-radius': '0px',
'border-bottom-style': 'solid',
'border-bottom-width': '12px',
'border-collapse': 'separate',
'border-image-outset': '0px',
'border-image-repeat': 'stretch',
'border-image-slice': '100%',
'border-image-source': 'none',
'border-image-width': '1',
'border-left-color': 'rgb(0, 0, 0)',
'border-left-style': 'solid',
'border-left-width': '12px',
'border-right-color': 'rgb(0, 0, 0)',
'border-right-style': 'solid',
'border-right-width': '12px',
'border-top-color': 'rgb(0, 0, 0)',
'border-top-left-radius': '0px',
'border-top-right-radius': '0px',
'border-top-style': 'solid',
'border-top-width': '12px',
I am not sure which border property you want to test for, but here is a working example
image.getStyleProperty('border-bottom-color'); outputs rgb(0, 0, 0)
I have a Sign In button that has an opacity of 50% normally but when you enter text in both the username and password or you click the Sign In button it is supposed to have an opacity of 100% (no transparency left at all). However, when the button is clicked it changes the background color but the opacity remains at 50%. Does anyone know why the opacity is not getting updated?
let readyForSignIn = this.state.email && this.state.password ? true : false;
let updateButton = this.state.loggingIn || readyForSignIn;
<TouchableOpacity style={[styles.buttonContainer, updateButton ? styles.buttonActive : styles.buttonDefault]} onPress={() => this.onSubmitEmail()}>
{this.state.loggingIn ?
<Text style={[styles.buttonText, {color: '#000'}]}>
Signing you in...
</Text>
:
<Text style={[styles.buttonText, {color: '#fff'}]}>
Sign In
</Text>
}
</TouchableOpacity>
and here are the styles for the button:
buttonContainer: {
marginTop: 20,
backgroundColor: '#3A3A3A',
paddingVertical: 16,
borderRadius: 3,
shadowOpacity: 0.35,
shadowColor: '#000',
shadowOffset: {widget: 0, height: 2},
shadowOpacity: 2
},
buttonDefault: {
opacity: 0.5
},
buttonActive: {
backgroundColor: '#fce443',
opacity: 1
},
I made a video of the issue as well:
https://www.youtube.com/watch?v=mp1fXVyHxoY&feature=youtu.be
Inline-style does not guarantee the order in which styles are applied (e.g. can be alphabetically order). So you should use the most specific style names you can.
For background opacity, use this instead:
buttonDefault: {
backgroundColor: rgba(58, 58, 58, 0.5);
},
buttonActive: {
backgroundColor: rgba(252, 228, 67, 1);
},
I have this CSS :
shadowColor: '#444',
shadowOffset: { width: 5, height: 5 },
shadowOpacity: 0.2,
shadowRadius: 8,
backgroundColor: 'white',
borderRadius: 10,
I'd like to replicate this style on Sketch.
But it uses 'Blur' and 'Spread' property for the shadow.
And i've noticed it uses box-shadow if you try to do it manually.
My question is :
I have this CSS styling. How could i apply it to my Shape.
(with or without plugin)
Sketch Version 47.1
For me, the style that you have would be translated like this in sketch app :
shadowColor: '#444', // Color #444
shadowOffset: { width: 5, height: 5 }, // X & Y offset to 5px
shadowOpacity: 0.2, // Opacity 20 (the A in HSBA)
shadowRadius: 8, // Look like it's the Blur
backgroundColor: 'white', // Bg color of the shape
borderRadius: 10, // Border radius of the shape
It is what you need ?
PS : This is not some CSS syntax that you have in your code.