Skip to content

Commit be20ead

Browse files
committed
Fix tvOS build by disabling keyboard toolbar
1 parent ad359e7 commit be20ead

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

Sources/UIKitBackend/KeyboardToolbar.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import UIKit
88
/// items will not cause the toolbar to be updated. The toolbar is only updated when the view
99
/// containing the ``View/keyboardToolbar(animateChanges:body:)`` modifier is updated, so any
1010
/// state necessary for the toolbar should live in the view itself.
11+
@available(tvOS, unavailable)
1112
public protocol ToolbarItem {
1213
/// The type of bar button item used to represent this item in UIKit.
1314
associatedtype ItemType: UIBarButtonItem
@@ -19,6 +20,7 @@ public protocol ToolbarItem {
1920
func updateBarButtonItem(_ item: inout ItemType)
2021
}
2122

23+
@available(tvOS, unavailable)
2224
@resultBuilder
2325
public enum ToolbarBuilder {
2426
public enum Component {
@@ -56,6 +58,7 @@ public enum ToolbarBuilder {
5658
}
5759
}
5860

61+
@available(tvOS, unavailable)
5962
extension Button: ToolbarItem {
6063
public final class ItemType: UIBarButtonItem {
6164
var callback: () -> Void
@@ -91,6 +94,7 @@ extension Button: ToolbarItem {
9194
}
9295

9396
@available(iOS 14, macCatalyst 14, tvOS 14, *)
97+
@available(tvOS, unavailable)
9498
extension Spacer: ToolbarItem {
9599
public func createBarButtonItem() -> UIBarButtonItem {
96100
if let minLength, minLength > 0 {
@@ -110,6 +114,7 @@ extension Spacer: ToolbarItem {
110114
}
111115
}
112116

117+
@available(tvOS, unavailable)
113118
struct FixedWidthToolbarItem<Base: ToolbarItem>: ToolbarItem {
114119
var base: Base
115120
var width: Int?
@@ -132,6 +137,7 @@ struct FixedWidthToolbarItem<Base: ToolbarItem>: ToolbarItem {
132137

133138
// Setting width on a flexible space is ignored, you must use a fixed space from the outset
134139
@available(iOS 14, macCatalyst 14, tvOS 14, *)
140+
@available(tvOS, unavailable)
135141
struct FixedWidthSpacerItem: ToolbarItem {
136142
var width: Int?
137143

@@ -148,6 +154,7 @@ struct FixedWidthSpacerItem: ToolbarItem {
148154
}
149155
}
150156

157+
@available(tvOS, unavailable)
151158
struct ColoredToolbarItem<Base: ToolbarItem>: ToolbarItem {
152159
var base: Base
153160
var color: Color
@@ -164,13 +171,14 @@ struct ColoredToolbarItem<Base: ToolbarItem>: ToolbarItem {
164171
}
165172
}
166173

174+
@available(tvOS, unavailable)
167175
extension ToolbarItem {
168176
/// A toolbar item with the specified width.
169177
///
170178
/// If `width` is positive, the item will have that exact width. If `width` is zero or
171179
/// nil, the item will have its natural size.
172180
public func frame(width: Int?) -> any ToolbarItem {
173-
if #available(iOS 14, macCatalyst 14, tvOS 14, *),
181+
if #available(iOS 14, macCatalyst 14, *),
174182
self is Spacer || self is FixedWidthSpacerItem
175183
{
176184
FixedWidthSpacerItem(width: width)
@@ -185,6 +193,7 @@ extension ToolbarItem {
185193
}
186194
}
187195

196+
@available(tvOS, unavailable)
188197
indirect enum ToolbarItemLocation: Hashable {
189198
case expression(inside: ToolbarItemLocation?)
190199
case block(index: Int, inside: ToolbarItemLocation?)
@@ -194,6 +203,7 @@ indirect enum ToolbarItemLocation: Hashable {
194203
case eitherSecond(inside: ToolbarItemLocation?)
195204
}
196205

206+
@available(tvOS, unavailable)
197207
final class KeyboardToolbar: UIToolbar {
198208
var locations: [ToolbarItemLocation: UIBarButtonItem] = [:]
199209

@@ -205,7 +215,7 @@ final class KeyboardToolbar: UIToolbar {
205215
var newLocations: [ToolbarItemLocation: UIBarButtonItem] = [:]
206216

207217
visitItems(component: components, inside: nil) { location, expression in
208-
var item =
218+
let item =
209219
if let oldItem = locations[location] {
210220
updateErasedItem(expression, oldItem)
211221
} else {
@@ -270,10 +280,12 @@ final class KeyboardToolbar: UIToolbar {
270280
}
271281
}
272282

283+
@available(tvOS, unavailable)
273284
enum ToolbarKey: EnvironmentKey {
274285
static let defaultValue: ((KeyboardToolbar) -> Void)? = nil
275286
}
276287

288+
@available(tvOS, unavailable)
277289
extension EnvironmentValues {
278290
var updateToolbar: ((KeyboardToolbar) -> Void)? {
279291
get { self[ToolbarKey.self] }
@@ -287,6 +299,7 @@ extension View {
287299
/// - animateChanges: Whether to animate updates when an item is added, removed, or
288300
/// updated
289301
/// - body: The toolbar's contents
302+
@available(tvOS, unavailable)
290303
public func keyboardToolbar(
291304
animateChanges: Bool = true,
292305
@ToolbarBuilder body: @escaping () -> ToolbarBuilder.FinalResult

Sources/UIKitBackend/UIKitBackend+Control.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,17 @@ extension UIKitBackend {
227227
textFieldWidget.onChange = onChange
228228
textFieldWidget.onSubmit = onSubmit
229229

230-
if let updateToolbar = environment.updateToolbar {
231-
let toolbar =
232-
(textFieldWidget.child.inputAccessoryView as? KeyboardToolbar) ?? KeyboardToolbar()
233-
updateToolbar(toolbar)
234-
textFieldWidget.child.inputAccessoryView = toolbar
235-
} else {
236-
textFieldWidget.child.inputAccessoryView = nil
237-
}
230+
#if os(iOS)
231+
if let updateToolbar = environment.updateToolbar {
232+
let toolbar =
233+
(textFieldWidget.child.inputAccessoryView as? KeyboardToolbar)
234+
?? KeyboardToolbar()
235+
updateToolbar(toolbar)
236+
textFieldWidget.child.inputAccessoryView = toolbar
237+
} else {
238+
textFieldWidget.child.inputAccessoryView = nil
239+
}
240+
#endif
238241
}
239242

240243
public func setContent(ofTextField textField: Widget, to content: String) {

0 commit comments

Comments
 (0)