Skip to content

Commit cb8d19f

Browse files
authored
Merge pull request #158 from skiptools/button
Bridge Button
2 parents 19f74ee + 451561d commit cb8d19f

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

Sources/SkipUI/SkipUI/Controls/Button.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public struct Button : View, ListItemAdapting {
6666
}
6767

6868
// SKIP @bridge
69-
public init(bridgedLabel: any View, action: @escaping () -> Void) {
70-
self.label = ComposeBuilder.from { bridgedLabel }
69+
public init(bridgedRole: Int?, action: @escaping () -> Void, bridgedLabel: any View) {
70+
self.role = bridgedRole == nil ? nil : ButtonRole(rawValue: bridgedRole!)
7171
self.action = action
72-
self.role = nil
72+
self.label = ComposeBuilder.from { bridgedLabel }
7373
}
7474

7575
#if SKIP
@@ -194,11 +194,11 @@ public struct ButtonStyle: RawRepresentable, Equatable {
194194
self.rawValue = rawValue
195195
}
196196

197-
public static let automatic = ButtonStyle(rawValue: 0)
198-
public static let plain = ButtonStyle(rawValue: 1)
199-
public static let borderless = ButtonStyle(rawValue: 2)
200-
public static let bordered = ButtonStyle(rawValue: 3)
201-
public static let borderedProminent = ButtonStyle(rawValue: 4)
197+
public static let automatic = ButtonStyle(rawValue: 0) // For bridging
198+
public static let plain = ButtonStyle(rawValue: 1) // For bridging
199+
public static let borderless = ButtonStyle(rawValue: 2) // For bridging
200+
public static let bordered = ButtonStyle(rawValue: 3) // For bridging
201+
public static let borderedProminent = ButtonStyle(rawValue: 4) // For bridging
202202
}
203203

204204
public enum ButtonRepeatBehavior : Hashable {
@@ -207,20 +207,25 @@ public enum ButtonRepeatBehavior : Hashable {
207207
case disabled
208208
}
209209

210-
public enum ButtonRole : Equatable {
211-
case destructive
212-
case cancel
210+
public enum ButtonRole : Int, Equatable {
211+
case destructive = 1 // For bridging
212+
case cancel = 2 // For bridging
213213
}
214214

215215
extension View {
216-
public func buttonStyle(_ style: ButtonStyle) -> some View {
216+
public func buttonStyle(_ style: ButtonStyle) -> any View {
217217
#if SKIP
218218
return environment(\._buttonStyle, style)
219219
#else
220220
return self
221221
#endif
222222
}
223223

224+
// SKIP @bridge
225+
public func buttonStyle(bridgedStyle: Int) -> any View {
226+
return buttonStyle(ButtonStyle(rawValue: bridgedStyle))
227+
}
228+
224229
@available(*, unavailable)
225230
public func buttonRepeatBehavior(_ behavior: ButtonRepeatBehavior) -> some View {
226231
return self

Sources/SkipUI/SkipUI/View/View.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ extension View {
412412
return self
413413
}
414414

415-
public func disabled(_ disabled: Bool) -> some View {
415+
// SKIP @bridge
416+
public func disabled(_ disabled: Bool) -> any View {
416417
#if SKIP
417418
return environment(\.isEnabled, !disabled)
418419
#else
@@ -1121,7 +1122,8 @@ extension View {
11211122
#endif
11221123
}
11231124

1124-
public func tint(_ color: Color?) -> some View {
1125+
// SKIP @bridge
1126+
public func tint(_ color: Color?) -> any View {
11251127
#if SKIP
11261128
return environment(\._tint, color)
11271129
#else

0 commit comments

Comments
 (0)