Skip to content

Commit 640d92c

Browse files
stephencelisgithub-actions[bot]
authored andcommitted
Run swift-format
1 parent 3d2bc6e commit 640d92c

27 files changed

+4569
-4558
lines changed

Sources/SwiftUINavigation/Alert.swift

Lines changed: 270 additions & 270 deletions
Large diffs are not rendered by default.

Sources/SwiftUINavigation/Binding.swift

Lines changed: 177 additions & 177 deletions
Large diffs are not rendered by default.

Sources/SwiftUINavigation/ConfirmationDialog.swift

Lines changed: 280 additions & 280 deletions
Large diffs are not rendered by default.
Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,92 @@
11
#if canImport(SwiftUI)
2-
import SwiftUI
2+
import SwiftUI
33

4-
extension View {
5-
/// Presents a full-screen cover using a binding as a data source for the sheet's content.
6-
///
7-
/// SwiftUI comes with a `fullScreenCover(item:)` view modifier that is powered by a binding to
8-
/// some hashable state. When this state becomes non-`nil`, it passes an unwrapped value to the
9-
/// content closure. This value, however, is completely static, which prevents the sheet from
10-
/// modifying it.
11-
///
12-
/// This overload differs in that it passes a _binding_ to the unwrapped value, instead. This
13-
/// gives the sheet the ability to write changes back to its source of truth.
14-
///
15-
/// Also unlike `fullScreenCover(item:)`, the binding's value does _not_ need to be hashable.
16-
///
17-
/// ```swift
18-
/// struct TimelineView: View {
19-
/// @State var draft: Post?
20-
///
21-
/// var body: Body {
22-
/// Button("Compose") {
23-
/// self.draft = Post()
24-
/// }
25-
/// .fullScreenCover(unwrapping: self.$draft) { $draft in
26-
/// ComposeView(post: $draft, onSubmit: { ... })
27-
/// }
28-
/// }
29-
/// }
30-
///
31-
/// struct ComposeView: View {
32-
/// @Binding var post: Post
33-
/// var body: some View { ... }
34-
/// }
35-
/// ```
36-
///
37-
/// - Parameters:
38-
/// - value: A binding to a source of truth for the sheet. When `value` is non-`nil`, a
39-
/// non-optional binding to the value is passed to the `content` closure. You use this binding
40-
/// to produce content that the system presents to the user in a sheet. Changes made to the
41-
/// sheet's binding will be reflected back in the source of truth. Likewise, changes to
42-
/// `value` are instantly reflected in the sheet. If `value` becomes `nil`, the sheet is
43-
/// dismissed.
44-
/// - onDismiss: The closure to execute when dismissing the sheet.
45-
/// - content: A closure returning the content of the sheet.
46-
@available(iOS 14, tvOS 14, watchOS 7, *)
47-
@available(macOS, unavailable)
48-
public func fullScreenCover<Value, Content>(
49-
unwrapping value: Binding<Value?>,
50-
onDismiss: (() -> Void)? = nil,
51-
@ViewBuilder content: @escaping (Binding<Value>) -> Content
52-
) -> some View
53-
where Content: View {
54-
self.fullScreenCover(
55-
isPresented: value.isPresent(),
56-
onDismiss: onDismiss
57-
) {
58-
Binding(unwrapping: value).map(content)
4+
extension View {
5+
/// Presents a full-screen cover using a binding as a data source for the sheet's content.
6+
///
7+
/// SwiftUI comes with a `fullScreenCover(item:)` view modifier that is powered by a binding to
8+
/// some hashable state. When this state becomes non-`nil`, it passes an unwrapped value to the
9+
/// content closure. This value, however, is completely static, which prevents the sheet from
10+
/// modifying it.
11+
///
12+
/// This overload differs in that it passes a _binding_ to the unwrapped value, instead. This
13+
/// gives the sheet the ability to write changes back to its source of truth.
14+
///
15+
/// Also unlike `fullScreenCover(item:)`, the binding's value does _not_ need to be hashable.
16+
///
17+
/// ```swift
18+
/// struct TimelineView: View {
19+
/// @State var draft: Post?
20+
///
21+
/// var body: Body {
22+
/// Button("Compose") {
23+
/// self.draft = Post()
24+
/// }
25+
/// .fullScreenCover(unwrapping: self.$draft) { $draft in
26+
/// ComposeView(post: $draft, onSubmit: { ... })
27+
/// }
28+
/// }
29+
/// }
30+
///
31+
/// struct ComposeView: View {
32+
/// @Binding var post: Post
33+
/// var body: some View { ... }
34+
/// }
35+
/// ```
36+
///
37+
/// - Parameters:
38+
/// - value: A binding to a source of truth for the sheet. When `value` is non-`nil`, a
39+
/// non-optional binding to the value is passed to the `content` closure. You use this binding
40+
/// to produce content that the system presents to the user in a sheet. Changes made to the
41+
/// sheet's binding will be reflected back in the source of truth. Likewise, changes to
42+
/// `value` are instantly reflected in the sheet. If `value` becomes `nil`, the sheet is
43+
/// dismissed.
44+
/// - onDismiss: The closure to execute when dismissing the sheet.
45+
/// - content: A closure returning the content of the sheet.
46+
@available(iOS 14, tvOS 14, watchOS 7, *)
47+
@available(macOS, unavailable)
48+
public func fullScreenCover<Value, Content>(
49+
unwrapping value: Binding<Value?>,
50+
onDismiss: (() -> Void)? = nil,
51+
@ViewBuilder content: @escaping (Binding<Value>) -> Content
52+
) -> some View
53+
where Content: View {
54+
self.fullScreenCover(
55+
isPresented: value.isPresent(),
56+
onDismiss: onDismiss
57+
) {
58+
Binding(unwrapping: value).map(content)
59+
}
5960
}
60-
}
6161

62-
/// Presents a full-screen cover using a binding and case path as a data source for the sheet's
63-
/// content.
64-
///
65-
/// A version of `fullScreenCover(unwrapping:)` that works with enum state.
66-
///
67-
/// - Parameters:
68-
/// - enum: A binding to an optional enum that holds the source of truth for the sheet at a
69-
/// particular case. When `enum` is non-`nil`, and `casePath` successfully extracts a value, a
70-
/// non-optional binding to the value is passed to the `content` closure. You use this binding
71-
/// to produce content that the system presents to the user in a sheet. Changes made to the
72-
/// sheet's binding will be reflected back in the source of truth. Likewise, changes to `enum`
73-
/// at the given case are instantly reflected in the sheet. If `enum` becomes `nil`, or
74-
/// becomes a case other than the one identified by `casePath`, the sheet is dismissed.
75-
/// - casePath: A case path that identifies a case of `enum` that holds a source of truth for
76-
/// the sheet.
77-
/// - onDismiss: The closure to execute when dismissing the sheet.
78-
/// - content: A closure returning the content of the sheet.
79-
@available(iOS 14, tvOS 14, watchOS 7, *)
80-
@available(macOS, unavailable)
81-
public func fullScreenCover<Enum, Case, Content>(
82-
unwrapping enum: Binding<Enum?>,
83-
case casePath: CasePath<Enum, Case>,
84-
onDismiss: (() -> Void)? = nil,
85-
@ViewBuilder content: @escaping (Binding<Case>) -> Content
86-
) -> some View
87-
where Content: View {
88-
self.fullScreenCover(unwrapping: `enum`.case(casePath), onDismiss: onDismiss, content: content)
62+
/// Presents a full-screen cover using a binding and case path as a data source for the sheet's
63+
/// content.
64+
///
65+
/// A version of `fullScreenCover(unwrapping:)` that works with enum state.
66+
///
67+
/// - Parameters:
68+
/// - enum: A binding to an optional enum that holds the source of truth for the sheet at a
69+
/// particular case. When `enum` is non-`nil`, and `casePath` successfully extracts a value, a
70+
/// non-optional binding to the value is passed to the `content` closure. You use this binding
71+
/// to produce content that the system presents to the user in a sheet. Changes made to the
72+
/// sheet's binding will be reflected back in the source of truth. Likewise, changes to `enum`
73+
/// at the given case are instantly reflected in the sheet. If `enum` becomes `nil`, or
74+
/// becomes a case other than the one identified by `casePath`, the sheet is dismissed.
75+
/// - casePath: A case path that identifies a case of `enum` that holds a source of truth for
76+
/// the sheet.
77+
/// - onDismiss: The closure to execute when dismissing the sheet.
78+
/// - content: A closure returning the content of the sheet.
79+
@available(iOS 14, tvOS 14, watchOS 7, *)
80+
@available(macOS, unavailable)
81+
public func fullScreenCover<Enum, Case, Content>(
82+
unwrapping enum: Binding<Enum?>,
83+
case casePath: CasePath<Enum, Case>,
84+
onDismiss: (() -> Void)? = nil,
85+
@ViewBuilder content: @escaping (Binding<Case>) -> Content
86+
) -> some View
87+
where Content: View {
88+
self.fullScreenCover(
89+
unwrapping: `enum`.case(casePath), onDismiss: onDismiss, content: content)
90+
}
8991
}
90-
}
91-
#endif // canImport(SwiftUI)
92+
#endif // canImport(SwiftUI)
Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
11
#if canImport(SwiftUI)
2-
import SwiftUI
2+
import SwiftUI
33

4-
/// A view that computes content by extracting a case from a binding to an enum and passing a
5-
/// non-optional binding to the case's associated value to its content closure.
6-
///
7-
/// Useful when working with enum state and building views that require the associated value at a
8-
/// particular case.
9-
///
10-
/// For example, a warehousing application may model the status of an inventory item using an enum.
11-
/// ``IfCaseLet`` can be used to produce bindings to the associated values of each case.
12-
///
13-
/// ```swift
14-
/// enum ItemStatus {
15-
/// case inStock(quantity: Int)
16-
/// case outOfStock(isOnBackOrder: Bool)
17-
/// }
18-
///
19-
/// struct InventoryItemView: View {
20-
/// @State var status: ItemStatus
21-
///
22-
/// var body: some View {
23-
/// IfCaseLet(self.$status, pattern: /ItemStatus.inStock) { $quantity in
24-
/// HStack {
25-
/// Text("Quantity: \(quantity)")
26-
/// Stepper("Quantity", value: $quantity)
27-
/// }
28-
/// Button("Out of stock") { self.status = .outOfStock(isOnBackOrder: false) }
29-
/// }
30-
/// IfCaseLet(self.$status, pattern: /ItemStatus.outOfStock) { $isOnBackOrder in
31-
/// Toggle("Is on back order?", isOn: $isOnBackOrder)
32-
/// Button("In stock") { self.status = .inStock(quantity: 1) }
33-
/// }
34-
/// }
35-
/// }
36-
/// ```
37-
///
38-
/// To exhaustively handle every case of a binding to an enum, see ``Switch``. Or, to unwrap a
39-
/// binding to an optional, see ``IfLet``.
40-
public struct IfCaseLet<Enum, Case, IfContent, ElseContent>: View
41-
where IfContent: View, ElseContent: View {
42-
public let `enum`: Binding<Enum>
43-
public let casePath: CasePath<Enum, Case>
44-
public let ifContent: (Binding<Case>) -> IfContent
45-
public let elseContent: ElseContent
46-
47-
/// Computes content by extracting a case from a binding to an enum and passing a non-optional
48-
/// binding to the case's associated value to its content closure.
4+
/// A view that computes content by extracting a case from a binding to an enum and passing a
5+
/// non-optional binding to the case's associated value to its content closure.
496
///
50-
/// - Parameters:
51-
/// - enum: A binding to an enum that holds the source of truth for the content at a particular
52-
/// case. When `casePath` successfully extracts a value from `enum`, a non-optional binding to
53-
/// the value is passed to the `content` closure. The closure can use this binding to produce
54-
/// its content and write changes back to the source of truth. Upstream changes to the case's
55-
/// value will also be instantly reflected in the presented content. If `enum` becomes a
56-
/// different case, nothing is computed.
57-
/// - casePath: A case path that identifies a case of `enum` that holds a source of truth for
58-
/// the content.
59-
/// - ifContent: A closure for computing content when `enum` matches a particular case.
60-
/// - elseContent: A closure for computing content when `enum` does not match the case.
61-
public init(
62-
_ `enum`: Binding<Enum>,
63-
pattern casePath: CasePath<Enum, Case>,
64-
@ViewBuilder then ifContent: @escaping (Binding<Case>) -> IfContent,
65-
@ViewBuilder else elseContent: () -> ElseContent
66-
) {
67-
self.casePath = casePath
68-
self.elseContent = elseContent()
69-
self.enum = `enum`
70-
self.ifContent = ifContent
71-
}
7+
/// Useful when working with enum state and building views that require the associated value at a
8+
/// particular case.
9+
///
10+
/// For example, a warehousing application may model the status of an inventory item using an enum.
11+
/// ``IfCaseLet`` can be used to produce bindings to the associated values of each case.
12+
///
13+
/// ```swift
14+
/// enum ItemStatus {
15+
/// case inStock(quantity: Int)
16+
/// case outOfStock(isOnBackOrder: Bool)
17+
/// }
18+
///
19+
/// struct InventoryItemView: View {
20+
/// @State var status: ItemStatus
21+
///
22+
/// var body: some View {
23+
/// IfCaseLet(self.$status, pattern: /ItemStatus.inStock) { $quantity in
24+
/// HStack {
25+
/// Text("Quantity: \(quantity)")
26+
/// Stepper("Quantity", value: $quantity)
27+
/// }
28+
/// Button("Out of stock") { self.status = .outOfStock(isOnBackOrder: false) }
29+
/// }
30+
/// IfCaseLet(self.$status, pattern: /ItemStatus.outOfStock) { $isOnBackOrder in
31+
/// Toggle("Is on back order?", isOn: $isOnBackOrder)
32+
/// Button("In stock") { self.status = .inStock(quantity: 1) }
33+
/// }
34+
/// }
35+
/// }
36+
/// ```
37+
///
38+
/// To exhaustively handle every case of a binding to an enum, see ``Switch``. Or, to unwrap a
39+
/// binding to an optional, see ``IfLet``.
40+
public struct IfCaseLet<Enum, Case, IfContent, ElseContent>: View
41+
where IfContent: View, ElseContent: View {
42+
public let `enum`: Binding<Enum>
43+
public let casePath: CasePath<Enum, Case>
44+
public let ifContent: (Binding<Case>) -> IfContent
45+
public let elseContent: ElseContent
7246

73-
public var body: some View {
74-
if let $case = Binding(unwrapping: self.enum, case: self.casePath) {
75-
self.ifContent($case)
76-
} else {
77-
self.elseContent
47+
/// Computes content by extracting a case from a binding to an enum and passing a non-optional
48+
/// binding to the case's associated value to its content closure.
49+
///
50+
/// - Parameters:
51+
/// - enum: A binding to an enum that holds the source of truth for the content at a particular
52+
/// case. When `casePath` successfully extracts a value from `enum`, a non-optional binding to
53+
/// the value is passed to the `content` closure. The closure can use this binding to produce
54+
/// its content and write changes back to the source of truth. Upstream changes to the case's
55+
/// value will also be instantly reflected in the presented content. If `enum` becomes a
56+
/// different case, nothing is computed.
57+
/// - casePath: A case path that identifies a case of `enum` that holds a source of truth for
58+
/// the content.
59+
/// - ifContent: A closure for computing content when `enum` matches a particular case.
60+
/// - elseContent: A closure for computing content when `enum` does not match the case.
61+
public init(
62+
_ `enum`: Binding<Enum>,
63+
pattern casePath: CasePath<Enum, Case>,
64+
@ViewBuilder then ifContent: @escaping (Binding<Case>) -> IfContent,
65+
@ViewBuilder else elseContent: () -> ElseContent
66+
) {
67+
self.casePath = casePath
68+
self.elseContent = elseContent()
69+
self.enum = `enum`
70+
self.ifContent = ifContent
71+
}
72+
73+
public var body: some View {
74+
if let $case = Binding(unwrapping: self.enum, case: self.casePath) {
75+
self.ifContent($case)
76+
} else {
77+
self.elseContent
78+
}
7879
}
7980
}
80-
}
8181

82-
extension IfCaseLet where ElseContent == EmptyView {
83-
public init(
84-
_ `enum`: Binding<Enum>,
85-
pattern casePath: CasePath<Enum, Case>,
86-
@ViewBuilder ifContent: @escaping (Binding<Case>) -> IfContent
87-
) {
88-
self.casePath = casePath
89-
self.elseContent = EmptyView()
90-
self.enum = `enum`
91-
self.ifContent = ifContent
82+
extension IfCaseLet where ElseContent == EmptyView {
83+
public init(
84+
_ `enum`: Binding<Enum>,
85+
pattern casePath: CasePath<Enum, Case>,
86+
@ViewBuilder ifContent: @escaping (Binding<Case>) -> IfContent
87+
) {
88+
self.casePath = casePath
89+
self.elseContent = EmptyView()
90+
self.enum = `enum`
91+
self.ifContent = ifContent
92+
}
9293
}
93-
}
94-
#endif // canImport(SwiftUI)
94+
#endif // canImport(SwiftUI)

0 commit comments

Comments
 (0)