Skip to content

Commit 952676f

Browse files
committed
Add support for iOS based targets
1 parent 7944e02 commit 952676f

5 files changed

Lines changed: 47 additions & 19 deletions

File tree

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ let package = Package(
99
.macOS("14.0"),
1010
.iOS("17.0"),
1111
.tvOS("17.0"),
12-
.watchOS("10.0")
12+
.watchOS("10.0"),
13+
.visionOS("1.0"),
1314
],
1415
products: [
1516
.library(name: "PredicateView", targets: ["PredicateView"]),

Sources/PredicateView/Expressions/CollectionExpression.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,7 @@ public struct CollectionExpressionView<Root, C>: HierarchicalExpressionView wher
144144
}
145145

146146
if isEnabled {
147-
MenuButton(label: Image(systemName: "plus.circle")) {
148-
menuItems
149-
}
150-
.tint(.accentColor)
151-
.fixedSize()
152-
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
147+
NewItemMenuButton { menuItems }
153148
}
154149
}
155150
}

Sources/PredicateView/Expressions/LogicalExpression.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,7 @@ public struct LogicalExpressionView<Root>: HierarchicalExpressionView {
123123
}
124124

125125
if isEnabled {
126-
MenuButton(label: Image(systemName: "plus.circle")) {
127-
menuItems
128-
}
129-
.tint(.accentColor)
130-
.fixedSize()
131-
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
126+
NewItemMenuButton { menuItems }
132127
}
133128
}
134129
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// NewItemMenuButton.swift
3+
// PredicateView
4+
//
5+
// Created by Phil Zakharchenko on 9/21/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct NewItemMenuButton<Content: View>: View {
11+
@ViewBuilder let menuItems: () -> Content
12+
13+
var body: some View {
14+
#if os(macOS)
15+
MenuButton(label: Image(systemName: "plus.circle")) {
16+
menuItems()
17+
}
18+
.tint(.accentColor)
19+
.fixedSize()
20+
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
21+
#else
22+
Menu {
23+
menuItems()
24+
} label: {
25+
Image(systemName: "plus.circle")
26+
}
27+
.tint(.accentColor)
28+
.fixedSize()
29+
.menuStyle(.borderlessButton)
30+
#endif
31+
}
32+
}

Sources/PredicateView/Views/TokenView.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ struct TokenView<Root, Header: View, Content: View, MenuItems: View, Widget: Vie
6060
.preference(key: PredicateDeletedStatusPreferenceKey.self, value: isDeleted)
6161
}
6262
}
63-
.contentShape(.rect)
63+
.background {
64+
shape
65+
.strokeBorder(Color.accentColor.opacity(0.3), lineWidth: 1)
66+
.fill(Color.accentColor.opacity(isFocused ? 0.15 : 0.1))
67+
}
68+
.contentShape(shape)
69+
.contentShape(.contextMenuPreview, shape)
6470
.onTapGesture {
6571
isFocused = true
6672
}
@@ -69,11 +75,6 @@ struct TokenView<Root, Header: View, Content: View, MenuItems: View, Widget: Vie
6975
menuItems
7076
}
7177
}
72-
.background {
73-
RoundedRectangle(cornerRadius: 6, style: .continuous)
74-
.strokeBorder(Color.accentColor.opacity(0.3), lineWidth: 1)
75-
.fill(Color.accentColor.opacity(isFocused ? 0.15 : 0.1))
76-
}
7778
.disabled(!isEnabled)
7879
}
7980

@@ -87,4 +88,8 @@ struct TokenView<Root, Header: View, Content: View, MenuItems: View, Widget: Vie
8788
isDeleted = true
8889
}
8990
}
91+
92+
private var shape: some InsettableShape {
93+
RoundedRectangle(cornerRadius: 6, style: .continuous)
94+
}
9095
}

0 commit comments

Comments
 (0)