Skip to content

Commit f25e550

Browse files
authored
Update CoreGlue (#227)
* Update CoreGlue API * Add OpenSwiftUIGlueTest * Fix CoreGlue API on non-Darwin platform issue
1 parent fad1d9c commit f25e550

File tree

8 files changed

+358
-151
lines changed

8 files changed

+358
-151
lines changed

Sources/OpenSwiftUI/CoreGlue/OpenSwiftUIGlue.swift Sources/OpenSwiftUI/Util/OpenSwiftUIGlue.swift

+36-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// Audited for iOS 18.0
66
// Status: WIP
77

8+
public import Foundation
89
@_spi(ForOpenSwiftUIOnly)
910
public import OpenSwiftUICore
11+
public import OpenGraphShims
1012
import COpenSwiftUI
1113

12-
#if canImport(Darwin)
13-
14-
public import Foundation
14+
// MARK: - OpenSwiftUIGlue
1515

1616
@_spi(ForOpenSwiftUIOnly)
1717
@_silgen_name("OpenSwiftUIGlueClass")
@@ -20,29 +20,62 @@ public func OpenSwiftUIGlueClass() -> CoreGlue.Type {
2020
}
2121

2222
@_spi(ForOpenSwiftUIOnly)
23+
#if canImport(ObjectiveC)
2324
@objc(OpenSwiftUIGlue)
25+
#endif
2426
final public class OpenSwiftUIGlue: CoreGlue {
27+
override final public func maxVelocity(_ velocity: CGFloat) {
28+
ViewGraph.current.nextUpdate.views.maxVelocity(velocity)
29+
}
30+
31+
override final public func nextUpdate(nextTime: Time, interval: Double, reason: UInt32?) {
32+
ViewGraph.current.nextUpdate.views.at(nextTime)
33+
ViewGraph.current.nextUpdate.views.interval(interval, reason: reason)
34+
}
35+
36+
override final public func hasTestHost() -> Bool {
37+
_TestApp.host != nil
38+
}
39+
40+
override final public func isInstantiated(graph: Graph) -> Bool {
41+
graph.viewGraph().isInstantiated
42+
}
43+
2544
override final public var defaultImplicitRootType: DefaultImplicitRootTypeResult {
2645
DefaultImplicitRootTypeResult(_VStackLayout.self)
2746
}
2847

48+
override final public var defaultSpacing: CGSize {
49+
CGSize(width: 8, height: 8)
50+
}
51+
2952
override final public func makeDefaultLayoutComputer() -> MakeDefaultLayoutComputerResult {
3053
MakeDefaultLayoutComputerResult(value: ViewGraph.current.$defaultLayoutComputer)
3154
}
55+
56+
override final public func makeDefaultLayoutComputer(graph: Graph) -> MakeDefaultLayoutComputerResult {
57+
MakeDefaultLayoutComputerResult(value: graph.viewGraph().$defaultLayoutComputer)
58+
}
59+
60+
// TODO
3261
}
3362

3463
@_spi(ForOpenSwiftUIOnly)
3564
@available(*, unavailable)
3665
extension OpenSwiftUIGlue: Sendable {}
3766

67+
// MARK: - OpenSwiftUIGlue2
68+
3869
@_spi(ForOpenSwiftUIOnly)
3970
@_silgen_name("OpenSwiftUIGlue2Class")
4071
public func OpenSwiftUIGlue2Class() -> CoreGlue2.Type {
4172
OpenSwiftUIGlue2.self
4273
}
4374

4475
@_spi(ForOpenSwiftUIOnly)
76+
#if canImport(ObjectiveC)
4577
@objc(OpenSwiftUIGlue2)
78+
#endif
4679
final public class OpenSwiftUIGlue2: CoreGlue2 {
4780
#if os(iOS)
4881
override public final func initializeTestApp() {
@@ -93,4 +126,3 @@ final public class OpenSwiftUIGlue2: CoreGlue2 {
93126
@_spi(ForOpenSwiftUIOnly)
94127
@available(*, unavailable)
95128
extension OpenSwiftUIGlue2: Sendable {}
96-
#endif

Sources/OpenSwiftUICore/CoreGlue/CoreGlue.swift

-126
This file was deleted.

Sources/OpenSwiftUICore/Data/Preference/View_Indirect.swift

-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ extension _ViewInputs {
1919
guard requestsLayoutComputer else {
2020
return outputs
2121
}
22-
#if canImport(Darwin)
2322
let defaultLayoutComputer = CoreGlue.shared.makeDefaultLayoutComputer().value
2423
@IndirectAttribute(source: defaultLayoutComputer)
2524
var indirect: LayoutComputer
2625
outputs.layoutComputer = $indirect
27-
#else
28-
preconditionFailure("#39")
29-
#endif
3026
return outputs
3127
}
3228
}

Sources/OpenSwiftUICore/Test/TestApp.swift

-8
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,23 @@ public struct _TestApp {
3434
package init() {}
3535

3636
package var body: some View {
37-
#if canImport(Darwin)
3837
CoreGlue2.shared.makeRootView(
3938
base: state.testView,
4039
rootFocusScope: rootFocusScope
4140
)
42-
#else
43-
state.testView
44-
#endif
4541
}
4642
}
4743

4844
package static let defaultEnvironment: EnvironmentValues = {
4945
var environment = EnvironmentValues()
50-
#if canImport(Darwin)
5146
CoreGlue2.shared.configureDefaultEnvironment(&environment)
52-
#endif
5347
// TODO
5448
return environment
5549
}()
5650

5751
/// Initialize a `_TestApp` for running tests.
5852
public init() {
59-
#if canImport(Darwin)
6053
CoreGlue2.shared.initializeTestApp()
61-
#endif
6254
}
6355

6456
package static var host: (any TestHost)?

Sources/OpenSwiftUICore/Text/DynamicTypeSize.swift

-4
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public enum DynamicTypeSize: Hashable, Comparable, CaseIterable, Sendable {
5858
}
5959

6060
package static var systemDefault: DynamicTypeSize {
61-
#if canImport(Darwin)
6261
CoreGlue2.shared.systemDefaultDynamicTypeSize
63-
#else
64-
.large
65-
#endif
6662
}
6763
}
6864

0 commit comments

Comments
 (0)