@@ -8,6 +8,7 @@ import UIKit
8
8
/// items will not cause the toolbar to be updated. The toolbar is only updated when the view
9
9
/// containing the ``View/keyboardToolbar(animateChanges:body:)`` modifier is updated, so any
10
10
/// state necessary for the toolbar should live in the view itself.
11
+ @available ( tvOS, unavailable)
11
12
public protocol ToolbarItem {
12
13
/// The type of bar button item used to represent this item in UIKit.
13
14
associatedtype ItemType : UIBarButtonItem
@@ -19,6 +20,7 @@ public protocol ToolbarItem {
19
20
func updateBarButtonItem( _ item: inout ItemType )
20
21
}
21
22
23
+ @available ( tvOS, unavailable)
22
24
@resultBuilder
23
25
public enum ToolbarBuilder {
24
26
public enum Component {
@@ -56,6 +58,7 @@ public enum ToolbarBuilder {
56
58
}
57
59
}
58
60
61
+ @available ( tvOS, unavailable)
59
62
extension Button : ToolbarItem {
60
63
public final class ItemType : UIBarButtonItem {
61
64
var callback : ( ) -> Void
@@ -90,7 +93,11 @@ extension Button: ToolbarItem {
90
93
}
91
94
}
92
95
93
- @available ( iOS 14 , macCatalyst 14 , tvOS 14 , * )
96
+ // Despite the fact that this is unavailable on tvOS, the `introduced: 14`
97
+ // clause is required for all current Swift versions to accept it.
98
+ // See https://forums.swift.org/t/contradictory-available-s-are-required/78831
99
+ @available ( iOS 14 , macCatalyst 14 , * )
100
+ @available ( tvOS, unavailable, introduced: 14 )
94
101
extension Spacer : ToolbarItem {
95
102
public func createBarButtonItem( ) -> UIBarButtonItem {
96
103
if let minLength, minLength > 0 {
@@ -110,6 +117,7 @@ extension Spacer: ToolbarItem {
110
117
}
111
118
}
112
119
120
+ @available ( tvOS, unavailable)
113
121
struct FixedWidthToolbarItem < Base: ToolbarItem > : ToolbarItem {
114
122
var base : Base
115
123
var width : Int ?
@@ -131,7 +139,8 @@ struct FixedWidthToolbarItem<Base: ToolbarItem>: ToolbarItem {
131
139
}
132
140
133
141
// Setting width on a flexible space is ignored, you must use a fixed space from the outset
134
- @available ( iOS 14 , macCatalyst 14 , tvOS 14 , * )
142
+ @available ( iOS 14 , macCatalyst 14 , * )
143
+ @available ( tvOS, unavailable, introduced: 14 )
135
144
struct FixedWidthSpacerItem : ToolbarItem {
136
145
var width : Int ?
137
146
@@ -148,6 +157,7 @@ struct FixedWidthSpacerItem: ToolbarItem {
148
157
}
149
158
}
150
159
160
+ @available ( tvOS, unavailable)
151
161
struct ColoredToolbarItem < Base: ToolbarItem > : ToolbarItem {
152
162
var base : Base
153
163
var color : Color
@@ -164,13 +174,14 @@ struct ColoredToolbarItem<Base: ToolbarItem>: ToolbarItem {
164
174
}
165
175
}
166
176
177
+ @available ( tvOS, unavailable)
167
178
extension ToolbarItem {
168
179
/// A toolbar item with the specified width.
169
180
///
170
181
/// If `width` is positive, the item will have that exact width. If `width` is zero or
171
182
/// nil, the item will have its natural size.
172
183
public func frame( width: Int ? ) -> any ToolbarItem {
173
- if #available( iOS 14 , macCatalyst 14 , tvOS 14 , * ) ,
184
+ if #available( iOS 14 , macCatalyst 14 , * ) ,
174
185
self is Spacer || self is FixedWidthSpacerItem
175
186
{
176
187
FixedWidthSpacerItem ( width: width)
@@ -185,6 +196,7 @@ extension ToolbarItem {
185
196
}
186
197
}
187
198
199
+ @available ( tvOS, unavailable)
188
200
indirect enum ToolbarItemLocation : Hashable {
189
201
case expression( inside: ToolbarItemLocation ? )
190
202
case block( index: Int , inside: ToolbarItemLocation ? )
@@ -194,6 +206,7 @@ indirect enum ToolbarItemLocation: Hashable {
194
206
case eitherSecond( inside: ToolbarItemLocation ? )
195
207
}
196
208
209
+ @available ( tvOS, unavailable)
197
210
final class KeyboardToolbar : UIToolbar {
198
211
var locations : [ ToolbarItemLocation : UIBarButtonItem ] = [ : ]
199
212
@@ -205,7 +218,7 @@ final class KeyboardToolbar: UIToolbar {
205
218
var newLocations : [ ToolbarItemLocation : UIBarButtonItem ] = [ : ]
206
219
207
220
visitItems ( component: components, inside: nil ) { location, expression in
208
- var item =
221
+ let item =
209
222
if let oldItem = locations [ location] {
210
223
updateErasedItem ( expression, oldItem)
211
224
} else {
@@ -270,10 +283,12 @@ final class KeyboardToolbar: UIToolbar {
270
283
}
271
284
}
272
285
286
+ @available ( tvOS, unavailable)
273
287
enum ToolbarKey : EnvironmentKey {
274
288
static let defaultValue : ( ( KeyboardToolbar ) -> Void ) ? = nil
275
289
}
276
290
291
+ @available ( tvOS, unavailable)
277
292
extension EnvironmentValues {
278
293
var updateToolbar : ( ( KeyboardToolbar ) -> Void ) ? {
279
294
get { self [ ToolbarKey . self] }
@@ -287,6 +302,7 @@ extension View {
287
302
/// - animateChanges: Whether to animate updates when an item is added, removed, or
288
303
/// updated
289
304
/// - body: The toolbar's contents
305
+ @available ( tvOS, unavailable)
290
306
public func keyboardToolbar(
291
307
animateChanges: Bool = true ,
292
308
@ToolbarBuilder body: @escaping ( ) -> ToolbarBuilder . FinalResult
0 commit comments