Skip to content

Commit 282033a

Browse files
authoredMar 10, 2024··
[Feature] Add empty separator interface and doc (#47)
1 parent a795f55 commit 282033a

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Divider.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: TODO
7+
8+
/// A visual element that can be used to separate other content.
9+
///
10+
/// When contained in a stack, the divider extends across the minor axis of the
11+
/// stack, or horizontally when not in a stack.
12+
public struct Divider: UnaryView, PrimitiveView {
13+
public init() {}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//
2+
// Spacer.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: TODO
7+
8+
import Foundation
9+
10+
/// A flexible space that expands along the major axis of its containing stack
11+
/// layout, or on both axes if not contained in a stack.
12+
///
13+
/// A spacer creates an adaptive view with no content that expands as much as
14+
/// it can. For example, when placed within an ``HStack``, a spacer expands
15+
/// horizontally as much as the stack allows, moving sibling views out of the
16+
/// way, within the limits of the stack's size.
17+
/// OpenSwiftUI sizes a stack that doesn't contain a spacer up to the combined
18+
/// ideal widths of the content of the stack's child views.
19+
///
20+
/// The following example provides a simple checklist row to illustrate how you
21+
/// can use a spacer:
22+
///
23+
/// struct ChecklistRow: View {
24+
/// let name: String
25+
///
26+
/// var body: some View {
27+
/// HStack {
28+
/// Image(systemName: "checkmark")
29+
/// Text(name)
30+
/// }
31+
/// .border(Color.blue)
32+
/// }
33+
/// }
34+
///
35+
/// ![A figure of a blue rectangular border that marks the boundary of an
36+
/// HStack, wrapping a checkmark image to the left of the name Megan. The
37+
/// checkmark and name are centered vertically and separated by system
38+
/// standard-spacing within the stack.](Spacer-1.png)
39+
///
40+
/// Adding a spacer before the image creates an adaptive view with no content
41+
/// that expands to push the image and text to the right side of the stack.
42+
/// The stack also now expands to take as much space as the parent view allows,
43+
/// shown by the blue border that indicates the boundary of the stack:
44+
///
45+
/// struct ChecklistRow: View {
46+
/// let name: String
47+
///
48+
/// var body: some View {
49+
/// HStack {
50+
/// Spacer()
51+
/// Image(systemName: "checkmark")
52+
/// Text(name)
53+
/// }
54+
/// .border(Color.blue)
55+
/// }
56+
/// }
57+
///
58+
/// ![A figure of a blue rectangular border that marks the boundary of an
59+
/// HStack, wrapping a checkmark image to the left of the name Megan. The
60+
/// checkmark and name are centered vertically, separated by system-standard
61+
/// spacing, and pushed to the right side of the stack.](Spacer-2.png)
62+
///
63+
/// Moving the spacer between the image and the name pushes those elements to
64+
/// the left and right sides of the ``HStack``, respectively. Because the stack
65+
/// contains the spacer, it expands to take as much horizontal space as the
66+
/// parent view allows; the blue border indicates its size:
67+
///
68+
/// struct ChecklistRow: View {
69+
/// let name: String
70+
///
71+
/// var body: some View {
72+
/// HStack {
73+
/// Image(systemName: "checkmark")
74+
/// Spacer()
75+
/// Text(name)
76+
/// }
77+
/// .border(Color.blue)
78+
/// }
79+
/// }
80+
///
81+
/// ![A figure of a blue rectangular border that marks the boundary of an
82+
/// HStack, wrapping a checkmark image to the left of the name Megan. The
83+
/// checkmark and name are centered vertically, with the checkmark on the
84+
/// left edge of the stack, and the text on the right side of the
85+
/// stack.](Spacer-3.png)
86+
///
87+
/// Adding two spacer views on the outside of the stack leaves the image and
88+
/// text together, while the stack expands to take as much horizontal space
89+
/// as the parent view allows:
90+
///
91+
/// struct ChecklistRow: View {
92+
/// let name: String
93+
///
94+
/// var body: some View {
95+
/// HStack {
96+
/// Spacer()
97+
/// Image(systemName: "checkmark")
98+
/// Text(name)
99+
/// Spacer()
100+
/// }
101+
/// .border(Color.blue)
102+
/// }
103+
/// }
104+
///
105+
/// ![A figure of a blue rectangular border marks the boundary of an HStack,
106+
/// wrapping a checkmark image to the left of text spelling the name Megan.
107+
/// The checkmark and name are centered vertically, separated by
108+
/// system-standard spacing, and centered horizontally
109+
/// in the stack.](Spacer-4.png)
110+
@frozen
111+
public struct Spacer {
112+
/// The minimum length this spacer can be shrunk to, along the axis or axes
113+
/// of expansion.
114+
///
115+
/// If `nil`, the system default spacing between views is used.
116+
public var minLength: CGFloat?
117+
118+
@inlinable
119+
public init(minLength: CGFloat? = nil) {
120+
self.minLength = minLength
121+
}
122+
}
123+
124+
extension Spacer: PrimitiveView {}

‎Sources/OpenSwiftUI/OpenSwiftUI.docc/Layout/LayoutFundamentals/Layout-Fundamentals.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ custom layout containers, see <doc:Custom-Layout>. For design guidance, see
1515
[Layout](https://developer.apple.com/design/human-interface-guidelines/foundations/layout) in the Human Interface Guidelines.
1616

1717
## Topics
18+
19+
### Separators
20+
21+
- ``Spacer``
22+
- ``Divider``

0 commit comments

Comments
 (0)
Please sign in to comment.