Skip to content

Commit 9d03a47

Browse files
authored
Add basic UIHostingView support (#53)
* Add UIHostingView * Update Time and UIHostingView * Move File location * Add basic ViewGraph support * Update ViewRendererHost implementation * Update UIHostingView's updateOutputs * Update VIew Layout related implementation * Fix Linux build issue
1 parent 0269c3a commit 9d03a47

36 files changed

+993
-122
lines changed

Package.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
77
"state" : {
88
"branch" : "main",
9-
"revision" : "ed01e7196afe56bf953f2f14b0b463208dda9c8d"
9+
"revision" : "ccb771c9fd939f1e1eefb46f69139e94ebb0dc82"
1010
}
1111
},
1212
{

Scripts/openswiftui_swiftinterface.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ cd $OPENSWIFTUI_ROOT
1111

1212
export OPENSWIFTUI_SWIFT_TESTING=0
1313
export OPENGRAPH_SWIFT_TESTING=0
14-
swift build -c release -Xswiftc -emit-module-interface -Xswiftc -enable-library-evolution
14+
swift build -Xswiftc -emit-module-interface -Xswiftc -enable-library-evolution
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// ScenePhase.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: WIP
7+
// ID: 130BB08D98602D712FD59CAC6992C14A
8+
9+
public enum ScenePhase: Comparable, Hashable {
10+
case background
11+
case inactive
12+
case active
13+
}
14+
15+
private struct ScenePhaseKey: EnvironmentKey {
16+
static let defaultValue: ScenePhase = .background
17+
}
18+
19+
extension EnvironmentValues {
20+
public var scenePhase: ScenePhase {
21+
get { self[ScenePhaseKey.self] }
22+
set { self[ScenePhaseKey.self] = newValue }
23+
}
24+
}

Sources/OpenSwiftUI/Core/Data/EnvironmentKeys/ColorSchemeKey.swift

-33
This file was deleted.

Sources/OpenSwiftUI/Core/Graph/GraphHost.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class GraphHost {
2020
private(set) var hostPreferenceValues: OptionalAttribute<PreferenceList>
2121
private(set) var lastHostPreferencesSeed: VersionSeed = .invalid
2222
private var pendingTransactions: [AsyncTransaction] = []
23-
private(set) var inTransaction = false
24-
private(set) var continuations: [() -> Void] = []
23+
/*private(set)*/ var inTransaction = false
24+
/*private(set)*/ var continuations: [() -> Void] = []
2525
private(set) var mayDeferUpdate = true
2626
private(set) var removedState: RemovedState = []
2727

@@ -156,7 +156,8 @@ class GraphHost {
156156
}
157157

158158
final func updatePreferences() -> Bool {
159-
fatalError("TODO")
159+
// fatalError("TODO")
160+
return false
160161
}
161162

162163
final func updateRemovedState() {

Sources/OpenSwiftUI/Core/Log/Signpost.swift

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct Signpost {
2424
}
2525
}
2626

27+
static let render = Signpost(style: .kdebug(0), stability: .published)
28+
static let renderUpdate = Signpost(style: .kdebug(0), stability: .published)
2729
static let viewHost = Signpost(style: .kdebug(0), stability: .published)
2830
}
2931

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// DisplayLink.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: WIP
7+
// ID: D912470A6161D66810B373079EE9F26A
8+
9+
#if canImport(Darwin) && os(iOS) // Disable macOS temporary due to CADisplayLink issue
10+
import QuartzCore
11+
#if os(iOS)
12+
import UIKit
13+
#elseif os(macOS)
14+
import AppKit
15+
#endif
16+
17+
final class DisplayLink: NSObject {
18+
private weak var host: AnyUIHostingView?
19+
private var link: CADisplayLink?
20+
private var nextUpdate: Time
21+
private var currentUpdate: Time?
22+
private var interval: Double
23+
private var reasons: Set<UInt32>
24+
private var currentThread: ThreadName
25+
private var nextThread: ThreadName
26+
27+
#if os(iOS)
28+
init(host: AnyUIHostingView, window: UIWindow) {
29+
fatalError("TODO")
30+
}
31+
#elseif os(macOS)
32+
init(host: AnyUIHostingView, window: NSWindow) {
33+
fatalError("TODO")
34+
}
35+
#endif
36+
37+
var willRender: Bool {
38+
nextUpdate < .infinity
39+
}
40+
41+
func setNextUpdate(delay: Double, interval: Double, reasons: Set<UInt32>) {
42+
// TODO
43+
}
44+
45+
func invalidate() {
46+
Update.lock.withLock {
47+
// TODO
48+
}
49+
}
50+
51+
@inline(__always)
52+
func startAsyncRendering() {
53+
nextThread = .async
54+
}
55+
56+
@inline(__always)
57+
func cancelAsyncRendering() {
58+
nextThread = .main
59+
}
60+
}
61+
62+
extension DisplayLink {
63+
enum ThreadName: Hashable {
64+
case main
65+
case async
66+
}
67+
}
68+
#endif

Sources/OpenSwiftUI/Core/Update/Update.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension MovableLock {
1919

2020
enum Update {
2121
static let trackHost: AnyObject = TraceHost()
22-
private static let lock = MovableLock.create()
22+
static let lock = MovableLock.create()
2323
private static var depth = 0
2424
private static var actions: [() -> Void] = []
2525

@@ -63,15 +63,15 @@ enum Update {
6363
}
6464
}
6565

66-
@inlinable
66+
@inline(__always)
6767
static func dispatchActions() {
6868
// FIXME
6969
for action in actions {
7070
action()
7171
}
7272
}
7373

74-
@inlinable
74+
@inline(__always)
7575
static func syncMain(_ body: () -> Void) {
7676
// TODO
7777
fatalError("TODO")

Sources/OpenSwiftUI/Core/Util/Time.swift

+76
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// Audited for RELEASE_2021
66
// Status: Complete
77

8+
#if canImport(QuartzCore)
9+
import QuartzCore
10+
#endif
11+
812
struct Time: Comparable, Hashable {
913
var seconds : Double
1014

@@ -14,4 +18,76 @@ struct Time: Comparable, Hashable {
1418

1519
static let zero = Time(seconds: .zero)
1620
static let infinity = Time(seconds: .infinity)
21+
22+
#if canImport(QuartzCore)
23+
@inline(__always)
24+
static var now: Time {
25+
Time(seconds: CACurrentMediaTime())
26+
}
27+
#endif
28+
29+
@inline(__always)
30+
private init(seconds: Double) {
31+
self.seconds = seconds
32+
}
33+
34+
@inline(__always)
35+
static func seconds(_ value: Double) -> Time {
36+
Time(seconds: value)
37+
}
38+
39+
@inline(__always)
40+
static func seconds(_ value: Int) -> Time {
41+
Time(seconds: Double(value))
42+
}
43+
44+
@inline(__always)
45+
static func microseconds(_ value: Double) -> Time {
46+
Time(seconds: value * 1e-3)
47+
}
48+
49+
@inline(__always)
50+
static func milliseconds(_ value: Double) -> Time {
51+
Time(seconds: value * 1e-6)
52+
}
53+
54+
@inline(__always)
55+
static func nanoseconds(_ value: Double) -> Time {
56+
Time(seconds: value * 1e-9)
57+
}
58+
59+
@inline(__always)
60+
static func += (lhs: inout Time, rhs: Time) {
61+
lhs.seconds = lhs.seconds + rhs.seconds
62+
}
63+
64+
@inline(__always)
65+
static func + (lhs: Time, rhs: Time) -> Time {
66+
Time(seconds: lhs.seconds + rhs.seconds)
67+
}
68+
69+
@inline(__always)
70+
static func -= (lhs: inout Time, rhs: Time) {
71+
lhs.seconds = lhs.seconds - rhs.seconds
72+
}
73+
74+
@inline(__always)
75+
static func - (lhs: Time, rhs: Time) -> Time {
76+
Time(seconds: lhs.seconds - rhs.seconds)
77+
}
78+
79+
@inline(__always)
80+
mutating func advancing(by seconds: Double) {
81+
self.seconds += seconds
82+
}
83+
84+
@inline(__always)
85+
func advanced(by seconds: Double) -> Time {
86+
Time(seconds: self.seconds + seconds)
87+
}
88+
89+
@inline(__always)
90+
func distance(to other: Time) -> Double {
91+
seconds.distance(to: other.seconds)
92+
}
1793
}

0 commit comments

Comments
 (0)