Skip to content

Instantly share code, notes, and snippets.

@jasonmerino
Created October 7, 2019 15:43
Show Gist options
  • Save jasonmerino/d07d683ea28b2cd0b9d4dcf6954c73e8 to your computer and use it in GitHub Desktop.
Save jasonmerino/d07d683ea28b2cd0b9d4dcf6954c73e8 to your computer and use it in GitHub Desktop.
import React, { FC } from 'react';
import {
ViewProps,
View,
FlexAlignType,
ViewStyle,
StyleProp,
} from 'react-native';
interface IProps extends ViewProps {
alignHorizontal?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'space-between'
| 'space-around'
| 'space-evenly';
alignVertical?: FlexAlignType;
flex?: boolean;
}
export const Row: FC<IProps> = props => {
const { style, flex, alignVertical, alignHorizontal, ...viewProps } = props;
const styles: StyleProp<ViewStyle>[] = [style, { flexDirection: 'row' }];
if (flex) {
styles.push({ flex: 1 });
}
if (alignVertical !== undefined) {
styles.push({ alignItems: alignVertical });
}
if (alignHorizontal !== undefined) {
styles.push({ justifyContent: alignHorizontal });
}
return <View style={styles} {...viewProps} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment