Last active
January 4, 2022 14:58
-
-
Save ryonakae/29f0f320ac577f2af5723986f6067b4e to your computer and use it in GitHub Desktop.
HStack / VStack / Spacer component on React Native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { StyleSheet, StyleProp, ViewStyle, View, FlexAlignType, ViewProps } from 'react-native' | |
type HStackProps = ViewProps & { | |
align?: FlexAlignType | |
style?: StyleProp<ViewStyle> | |
} | |
const HStack: React.FC<HStackProps> = ({ align = 'stretch', style, children, ...delegated }) => { | |
return ( | |
<View style={[styles.hStack, { alignItems: align }, style]} {...delegated}> | |
{children} | |
</View> | |
) | |
} | |
const styles = StyleSheet.create({ | |
hStack: { | |
flexDirection: 'row' | |
} | |
}) | |
export default HStack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { StyleSheet, View, ViewProps } from 'react-native' | |
type SpacerProps = ViewProps & { | |
x?: number | |
y?: number | |
} | |
const Spacer: React.FC<SpacerProps> = ({ x, y, style, ...delegated }) => { | |
const width = x || 1 | |
const height = y || 1 | |
return ( | |
<View | |
style={[ | |
{ | |
width, | |
minWidth: width, | |
height, | |
minHeight: height | |
}, | |
styles.spacer, | |
style | |
]} | |
{...delegated} | |
/> | |
) | |
} | |
const styles = StyleSheet.create({ | |
spacer: {} | |
}) | |
export default Spacer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { StyleSheet, StyleProp, ViewStyle, View, FlexAlignType, ViewProps } from 'react-native' | |
type VStackProps = ViewProps & { | |
align?: FlexAlignType | |
style?: StyleProp<ViewStyle> | |
} | |
const VStack: React.FC<VStackProps> = ({ align = 'stretch', style, children, ...delegated }) => { | |
return ( | |
<View style={[styles.vStack, { alignItems: align }, style]} {...delegated}> | |
{children} | |
</View> | |
) | |
} | |
const styles = StyleSheet.create({ | |
vStack: { | |
flexDirection: 'column' | |
} | |
}) | |
export default VStack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ref: