Skip to content

Commit 3b95f92

Browse files
authored
Add usage of _ViewInputs.textAlwaysOnProvider (#501)
1 parent 1f2bea8 commit 3b95f92

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

Sources/OpenSwiftUI/Animation/Timeline/AlwaysOnBridge.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ struct OpenSwiftUITextAlwaysOnProvider: TextAlwaysOnProvider {
181181
schedule: @autoclosure () -> Attribute<(any TimelineSchedule)?>,
182182
outputs: inout _ViewOutputs
183183
) {
184-
185184
guard _UIAlwaysOnEnvironment._alwaysOnSupported else {
186185
return
187186
}

Sources/OpenSwiftUI/Integration/Graphic/UIKit/UIKitConversions.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,25 @@ extension UITraitEnvironmentLayoutDirection {
235235
}
236236
}
237237

238+
// MARK: - UIUserInterfaceIdiom Conversions
239+
240+
extension UIUserInterfaceIdiom {
241+
package var idiom: AnyInterfaceIdiom? {
242+
switch self {
243+
case .phone: AnyInterfaceIdiom(.phone)
244+
case .pad: AnyInterfaceIdiom(.pad)
245+
case .tv: AnyInterfaceIdiom(.tv)
246+
case .carPlay: AnyInterfaceIdiom(.carPlay)
247+
case .watch: AnyInterfaceIdiom(.watch)
248+
case .mac: AnyInterfaceIdiom(.mac)
249+
case .vision: AnyInterfaceIdiom(.vision)
250+
default: nil
251+
}
252+
}
253+
}
254+
255+
extension UIUserInterfaceIdiom {
256+
static let watch = UIUserInterfaceIdiom(rawValue: 4)!
257+
}
258+
238259
#endif

Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
// ID: FAF0B683EB49BE9BABC9009857940A1E (SwiftUI)
88

99
#if os(iOS) || os(visionOS)
10+
public import UIKit
11+
import OpenAttributeGraphShims
1012
@_spi(ForOpenSwiftUIOnly)
1113
@_spi(Private)
1214
public import OpenSwiftUICore
13-
public import UIKit
14-
import OpenSwiftUI_SPI
15-
1615
import OpenSwiftUISymbolDualTestsSupport
16+
import OpenSwiftUI_SPI
1717

1818
/// A UIView which hosts an OpenSwiftUI View hierarchy.
1919
@available(macOS, unavailable)
@@ -143,7 +143,9 @@ open class _UIHostingView<Content>: UIView, XcodeViewDebugDataProvider where Con
143143
// AccessibilityFocus.changed(from: nil, to: nil, within: self)
144144
}
145145
}
146-
146+
147+
// private weak var delegate: UIHostingViewDelegate?
148+
147149
required public init(rootView: Content) {
148150
_rootView = rootView
149151
Update.begin()
@@ -167,6 +169,7 @@ open class _UIHostingView<Content>: UIView, XcodeViewDebugDataProvider where Con
167169
}
168170
// TODO
169171
super.init(frame: .zero)
172+
_base.viewGraph.append(feature: HostViewGraph(host: self))
170173
// TODO
171174
let base = base
172175
if let host = base.host {
@@ -718,4 +721,33 @@ extension _UIHostingView: UIViewControllerProvider {
718721
}
719722
}
720723

724+
// MARK: _UIHostingView.HostViewGraph [6.5.4] [Blocked by Gesture System]
725+
726+
extension _UIHostingView {
727+
private struct HostViewGraph: ViewGraphFeature {
728+
weak var host: _UIHostingView?
729+
730+
func modifyViewInputs(inputs: inout _ViewInputs, graph: ViewGraph) {
731+
guard let host else {
732+
return
733+
}
734+
// inputs.eventBindingBridgeFactory = UIKitResponderEventBindingBridge.Factory.self
735+
// inputs.gestureContainerFactory = UIKitGestureContainerFactory.self
736+
// host.delegate?.xx
737+
var idiom = inputs[InterfaceIdiomInput.self]
738+
if idiom == nil {
739+
Update.syncMain {
740+
idiom = host.traitCollection.userInterfaceIdiom.idiom ?? UIDevice.current.userInterfaceIdiom.idiom
741+
}
742+
}
743+
idiom.map { inputs[InterfaceIdiomInput.self] = $0 }
744+
let box: WeakBox<UIView> = WeakBox(host)
745+
let boxAttr = Attribute(value: box)
746+
// inputs[UIKitHostContainerFocusItemInput.self] = boxAttr
747+
inputs.textAlwaysOnProvider = OpenSwiftUITextAlwaysOnProvider.self
748+
// navigationBridge?.updateViewInputs(&inputs)
749+
}
750+
}
751+
}
752+
721753
#endif

Sources/OpenSwiftUICore/Event/Event/EventBindingSource.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ package struct EventBindingBridgeFactoryInput: ViewInput {
6565
}
6666

6767
extension _ViewInputs {
68+
@inline(__always)
69+
package var eventBindingBridgeFactory: (any EventBindingBridgeFactory.Type)? {
70+
get { self[EventBindingBridgeFactoryInput.self] }
71+
set { self[EventBindingBridgeFactoryInput.self] = newValue }
72+
}
73+
6874
package func makeEventBindingBridge(
6975
bindingManager: EventBindingManager,
7076
responder: any AnyGestureResponder
7177
) -> any EventBindingBridge & GestureGraphDelegate {
72-
guard let factory = self[EventBindingBridgeFactoryInput.self] else {
78+
guard let factory = eventBindingBridgeFactory else {
7379
preconditionFailure("Event binding factory must be configured")
7480
}
7581
return factory.makeEventBindingBridge(

Sources/OpenSwiftUICore/Event/Gesture/GestureContainerFactory.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// GestureContainerFactory.swift
33
// OpenSwiftUICore
44
//
5+
// Audited for 6.5.4
56
// Status: Complete
67

7-
// MARK: - GestureContainerFactory [6.5.4]
8+
// MARK: - GestureContainerFactory
89

910
package protocol GestureContainerFactory {
1011
static func makeGestureContainer(responder: any AnyGestureContainingResponder) -> AnyObject
@@ -17,8 +18,14 @@ package struct GestureContainerFactoryInput: ViewInput {
1718
}
1819

1920
extension _ViewInputs {
21+
@inline(__always)
22+
package var gestureContainerFactory: (any GestureContainerFactory.Type)? {
23+
get { self[GestureContainerFactoryInput.self] }
24+
set { self[GestureContainerFactoryInput.self] = newValue }
25+
}
26+
2027
package func makeGestureContainer(responder: any AnyGestureContainingResponder) -> AnyObject {
21-
guard let factory = self[GestureContainerFactoryInput.self] else {
28+
guard let factory = gestureContainerFactory else {
2229
preconditionFailure("Gesture container factory must be configured")
2330
}
2431
return factory.makeGestureContainer(responder: responder)

0 commit comments

Comments
 (0)