Skip to content

Commit 484070c

Browse files
committed
Address PR comments
1 parent 00a6724 commit 484070c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Sources/SwiftCrossUI/Environment/EnvironmentValues.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public struct EnvironmentValues {
4545
var onResize: (_ newSize: ViewSize) -> Void
4646

4747
// Backing storage for extensible subscript
48-
private var extraKeys: [ObjectIdentifier: Any]
48+
private var extraValues: [ObjectIdentifier: Any]
4949

5050
public subscript<T: EnvironmentKey>(_ key: T.Type) -> T.Value {
5151
get {
52-
extraKeys[ObjectIdentifier(T.self), default: T.defaultValue] as! T.Value
52+
extraValues[ObjectIdentifier(T.self), default: T.defaultValue] as! T.Value
5353
}
5454
set {
55-
extraKeys[ObjectIdentifier(T.self)] = newValue
55+
extraValues[ObjectIdentifier(T.self)] = newValue
5656
}
5757
}
5858

@@ -133,7 +133,7 @@ public struct EnvironmentValues {
133133
colorScheme = .light
134134
windowScaleFactor = 1
135135
window = nil
136-
extraKeys = [:]
136+
extraValues = [:]
137137
}
138138

139139
/// Returns a copy of the environment with the specified property set to the
@@ -145,7 +145,7 @@ public struct EnvironmentValues {
145145
}
146146
}
147147

148-
/// A key that can be used to extend the environment over the built-in values.
148+
/// A key that can be used to extend the environment with new properties.
149149
public protocol EnvironmentKey {
150150
/// The type of value the key can hold.
151151
associatedtype Value

Sources/UIKitBackend/KeyboardToolbar.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import UIKit
33

44
/// An item which can be displayed in a keyboard toolbar. Implementers of this do not have
55
/// to implement ``SwiftCrossUI/View``.
6+
///
7+
/// Toolbar items are expected to be "stateless". Mutations of `@State` properties of toolbar
8+
/// items will not cause the toolbar to be updated. The toolbar is only updated when the view
9+
/// containing the ``View/keyboardToolbar(animateChanges:body:)`` modifier is updated, so any
10+
/// state necessary for the toolbar should live in the view itself.
611
public protocol ToolbarItem {
712
/// Convert the item to a `UIBarButtonItem`, which will be placed in the keyboard toolbar.
813
func asBarButtonItem() -> UIBarButtonItem
@@ -39,10 +44,6 @@ public enum ToolbarBuilder {
3944
public static func buildEither(second component: Component) -> Component {
4045
component
4146
}
42-
43-
public static func buildFinalResult(_ component: Component) -> [UIBarButtonItem] {
44-
component.map { $0.asBarButtonItem() }
45-
}
4647
}
4748

4849
final class CallbackBarButtonItem: UIBarButtonItem {
@@ -80,9 +81,9 @@ extension Spacer: ToolbarItem {
8081
if let minLength, minLength > 0 {
8182
print(
8283
"""
83-
Warning: Spacer's minLength is ignored inside keyboard toolbars, as \
84-
flexible-length spacers cannot specify a minimum width. Use `.frame(width:)` \
85-
for a fixed-length spacer.
84+
Warning: Spacer's minLength property is ignored within keyboard toolbars \
85+
due to UIKit limitations. Use `Spacer()` for unconstrained spacers and \
86+
`Spacer().frame(width: _)` for fixed-length spacers.
8687
"""
8788
)
8889
}
@@ -168,11 +169,11 @@ extension View {
168169
/// - body: The toolbar's contents
169170
public func keyboardToolbar(
170171
animateChanges: Bool = true,
171-
@ToolbarBuilder body: @escaping () -> [UIBarButtonItem]
172+
@ToolbarBuilder body: @escaping () -> ToolbarBuilder.Component
172173
) -> some View {
173174
EnvironmentModifier(self) { environment in
174175
environment.with(\.updateToolbar) { toolbar in
175-
toolbar.setItems(body(), animated: animateChanges)
176+
toolbar.setItems(body().map { $0.asBarButtonItem() }, animated: animateChanges)
176177
toolbar.sizeToFit()
177178
}
178179
}

0 commit comments

Comments
 (0)