SwiftUI inspired Stack and Spacer components.
- VStack: Vertical Stack
- HStack: Horizontal Stack
- ZStack: Overlay Stack
- Spacer: Spacing within Stacks
yarn add react-native-stacksimport React from "react";
import { Text, Button } from "react-native";
import { VStack, HStack, Spacer } from "react-native-stacks";
function Example() {
return (
<VStack aligmment="leading" spacing={20}>
<Text>Orders</Text>
<Spacer />
<HStack>
<Button onPress={add} title="Add" />
<Spacer />
<Button onPress={remove} title="Remove" />
</HStack>
</VStack>
);
}vs. SwiftUI...
struct Example: View {
var body: some View {
VStack(alignment: .leading, spacing: 20) {
Text("Orders")
Spacer()
HStack() {
Button(action: add) {
Text("Add")
}
Spacer()
Button(action: remove) {
Text("Remove")
}
}
}
}
}A vertical stack.
The amount of space between each item in the stack.
required: no
type:
numberdefault:
0
The horizontal alignment for the stack items.
required: no
type:
VStackAlignmentdefault:
'center'
type VStackAlignment = "leading" | "center" | "trailing";A horizontal stack.
The amount of space between each item in the stack.
required: no
type:
numberdefault:
0
The vertical alignment for the stack items.
required: no
type:
HStackAlignmentdefault:
'center'
type HStackAlignment = "top" | "center" | "bottom";An overlay stack.
The horizontal and vertical alignment for the stack items. Since a ZStack overlays items on top of one another, we are able to align them both vertically and horizontally.
required: no
type:
ZStackAlignmentdefault:
'center'
type ZStackAlignment =
| "top"
| "center"
| "bottom"
| "leading"
| "trailing"
| "topLeading"
| "topTrailing"
| "bottomLeading"
| "bottomTrailing";A component to provide space between stack items. Spacers will fill the available space between components.
