Skip to content

Commit e9583c1

Browse files
committed
feat: add gap to row and add stacks component
1 parent 849ad80 commit e9583c1

File tree

3 files changed

+130
-18
lines changed

3 files changed

+130
-18
lines changed

src/Utils/Row.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
import * as React from 'react';
2-
import {View, StyleSheet, type ViewProps, type FlexStyle} from 'react-native';
1+
import * as React from "react";
2+
import { View, StyleSheet, type ViewProps, type FlexStyle } from "react-native";
33

44
const styles = StyleSheet.create({
55
default: {
6-
flexDirection: 'row',
6+
flexDirection: "row",
77
},
88
});
99

1010
type Props = {
11-
alignItems?: FlexStyle['alignItems'];
12-
justifyContent?: FlexStyle['justifyContent'];
13-
alignContent?: FlexStyle['alignContent'];
14-
alignSelf?: FlexStyle['alignSelf'];
11+
alignItems?: FlexStyle["alignItems"];
12+
justifyContent?: FlexStyle["justifyContent"];
13+
alignContent?: FlexStyle["alignContent"];
14+
alignSelf?: FlexStyle["alignSelf"];
15+
gap?: number;
1516
} & ViewProps;
1617

1718
/**
1819
* Row
1920
* - A View Component whose default flexDiretion is row
2021
*/
2122
export const Row: React.FC<Props> = React.memo(
22-
({style, alignItems, alignContent, justifyContent, alignSelf, ...rest}) => {
23+
({ style, alignItems, alignContent, justifyContent, alignSelf, ...rest }) => {
2324
return (
2425
<View
2526
style={[
2627
styles.default,
27-
{alignItems, alignContent, justifyContent, alignSelf},
28+
{ alignItems, alignContent, justifyContent, alignSelf, gap },
2829
StyleSheet.flatten(style),
2930
]}
3031
{...rest}
@@ -33,4 +34,4 @@ export const Row: React.FC<Props> = React.memo(
3334
},
3435
);
3536

36-
Row.displayName = 'Row';
37+
Row.displayName = "Row";

src/Utils/Stacks.tsx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import * as React from "react";
2+
import { View, StyleSheet, type ViewProps, type FlexStyle } from "react-native";
3+
4+
type StackProps = {
5+
gap?: number;
6+
padding?: number;
7+
paddingHorizontal?: number;
8+
flex?: number;
9+
paddingVertical?: number;
10+
borderBottomWidth?: number;
11+
borderTopWidth?: number;
12+
borderRightWidth?: number;
13+
borderLeftWidth?: number;
14+
borderColor?: string;
15+
alignItems?: FlexStyle["alignItems"];
16+
justifyContent?: FlexStyle["justifyContent"];
17+
alignContent?: FlexStyle["alignContent"];
18+
alignSelf?: FlexStyle["alignSelf"];
19+
} & ViewProps;
20+
export const XStack = React.memo<StackProps>(
21+
({
22+
gap,
23+
style,
24+
padding,
25+
paddingHorizontal,
26+
paddingVertical,
27+
borderBottomWidth,
28+
borderTopWidth,
29+
borderRightWidth,
30+
borderLeftWidth,
31+
borderColor,
32+
flex,
33+
justifyContent,
34+
alignItems,
35+
alignContent,
36+
alignSelf,
37+
...rest
38+
}) => (
39+
<View
40+
style={StyleSheet.flatten([
41+
styles.flexRow,
42+
{
43+
gap,
44+
padding,
45+
flex,
46+
paddingHorizontal,
47+
paddingVertical,
48+
borderBottomWidth,
49+
borderTopWidth,
50+
borderRightWidth,
51+
borderLeftWidth,
52+
borderColor,
53+
justifyContent,
54+
alignItems,
55+
},
56+
style,
57+
])}
58+
{...rest}
59+
/>
60+
),
61+
);
62+
XStack.displayName = "XStack";
63+
export const YStack = React.memo<StackProps>(
64+
({
65+
gap,
66+
padding,
67+
style,
68+
paddingHorizontal,
69+
paddingVertical,
70+
flex,
71+
borderBottomWidth,
72+
borderTopWidth,
73+
borderRightWidth,
74+
borderLeftWidth,
75+
borderColor,
76+
justifyContent,
77+
alignItems,
78+
alignContent,
79+
alignSelf,
80+
...rest
81+
}) => (
82+
<View
83+
style={StyleSheet.flatten([
84+
{
85+
gap,
86+
padding,
87+
flex,
88+
paddingHorizontal,
89+
paddingVertical,
90+
borderBottomWidth,
91+
borderTopWidth,
92+
borderRightWidth,
93+
borderLeftWidth,
94+
borderColor,
95+
justifyContent,
96+
alignItems,
97+
},
98+
style,
99+
])}
100+
{...rest}
101+
/>
102+
),
103+
);
104+
YStack.displayName = "YStack";
105+
106+
const styles = StyleSheet.create({
107+
flexRow: {
108+
flexDirection: "row",
109+
},
110+
});

src/Utils/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
export {Flex} from './Flex';
2-
export {Margin} from './Margin';
3-
export {PressableOpacity} from './PressableOpacity';
4-
export {Row} from './Row';
5-
export {Stack} from './Stack';
6-
export {StaticPage} from './StaticPage';
7-
export {FullPage} from './FullPage';
8-
export * from './Platform';
1+
export { Flex } from "./Flex";
2+
export { Margin } from "./Margin";
3+
export { PressableOpacity } from "./PressableOpacity";
4+
export { Row } from "./Row";
5+
export { Stack } from "./Stack";
6+
export * from "./Stacks";
7+
export { StaticPage } from "./StaticPage";
8+
export { FullPage } from "./FullPage";
9+
export * from "./Platform";

0 commit comments

Comments
 (0)