Skip to content

Commit b075f18

Browse files
committed
Allow logical expressions to be read-only
1 parent ec74f98 commit b075f18

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

Example/PredicateViewExample/CustomExpressionDemoView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,21 @@ struct StatusExpressionView: CustomExpressionView {
6464
/// The binding to the current status value.
6565
@Binding var value: Item.Status.RawValue?
6666

67+
@Environment(\.isEnabled) private var isEnabled
68+
6769
/// The body of the view, which creates a picker for selecting the status.
6870
var body: some View {
69-
Picker("", selection: $value) {
70-
ForEach(Item.Status.allCases, id: \.rawValue) { item in
71-
Text(item.rawValue)
72-
.tag(item.rawValue)
71+
if isEnabled {
72+
// The control is read-write. Allow the user to pick the status.
73+
Picker("", selection: $value) {
74+
ForEach(Item.Status.allCases, id: \.rawValue) { item in
75+
Text(item.rawValue)
76+
.tag(item.rawValue)
77+
}
7378
}
79+
} else {
80+
// The control is read-only; display text instead.
81+
Text(value ?? "")
7482
}
7583
}
7684
}

Sources/PredicateView/Expressions/LogicalExpression.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public struct LogicalExpressionView<Root>: HierarchicalExpressionView {
161161
NewItemMenuButton { menuItems }
162162
}
163163
}
164+
.fixedSize(horizontal: false, vertical: true)
164165
}
165166

166167
@ViewBuilder

Sources/PredicateView/Views/TokenView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ struct TokenView<Root, Header: View, Content: View, MenuItems: View, Widget: Vie
5050
}
5151
.padding(4)
5252

53+
widget
54+
5355
if isEnabled {
54-
widget
55-
5656
Menu("") { menuItems }
5757
.padding(6)
5858
.fixedSize()
5959
.menuStyle(.borderlessButton)
6060
.preference(key: PredicateDeletedStatusPreferenceKey.self, value: isDeleted)
6161
}
6262
}
63+
.frame(maxHeight: .infinity, alignment: .top)
6364
.background {
6465
shape
6566
.strokeBorder(Color.accentColor.opacity(0.3), lineWidth: 1)

0 commit comments

Comments
 (0)