Skip to content

Commit 14597bb

Browse files
authored
Update ViewGraph implementation (#58)
* Update GraphHost preference * Update EmptyView * Add LayoutDirection implementation * Add SafeAreaInsets API * Add RootGeometry * Update ViewGraph instantiateOutputs * Fix Linux build issue
1 parent 831c079 commit 14597bb

File tree

16 files changed

+559
-33
lines changed

16 files changed

+559
-33
lines changed

.swiftformat

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
--acronyms ID,URL,UUID
2+
--allman false
3+
--anonymousforeach convert
4+
--assetliterals visual-width
5+
--asynccapturing
6+
--beforemarks
7+
--binarygrouping 4,8
8+
--categorymark "MARK: %c"
9+
--classthreshold 0
10+
--closingparen balanced
11+
--closurevoid remove
12+
--commas always
13+
--conflictmarkers reject
14+
--decimalgrouping 3,6
15+
--elseposition same-line
16+
--emptybraces no-space
17+
--enumnamespaces always
18+
--enumthreshold 0
19+
--exponentcase lowercase
20+
--exponentgrouping disabled
21+
--extensionacl on-declarations
22+
--extensionlength 0
23+
--extensionmark "MARK: - %t + %c"
24+
--fractiongrouping disabled
25+
--fragment false
26+
--funcattributes preserve
27+
--generictypes
28+
--groupedextension "MARK: %c"
29+
--guardelse auto
30+
--header ignore
31+
--hexgrouping 4,8
32+
--hexliteralcase uppercase
33+
--ifdef no-indent
34+
--importgrouping alpha
35+
--indent 4
36+
--indentcase false
37+
--indentstrings false
38+
--lifecycle
39+
--lineaftermarks true
40+
--linebreaks lf
41+
--markcategories true
42+
--markextensions always
43+
--marktypes always
44+
--maxwidth none
45+
--modifierorder
46+
--nevertrailing
47+
--nospaceoperators
48+
--nowrapoperators
49+
--octalgrouping 4,8
50+
--onelineforeach ignore
51+
--operatorfunc spaced
52+
--organizetypes actor,class,enum,struct
53+
--patternlet hoist
54+
--ranges spaced
55+
--redundanttype inferred
56+
--self remove
57+
--selfrequired
58+
--semicolons inline
59+
--shortoptionals always
60+
--smarttabs enabled
61+
--someany false
62+
--stripunusedargs always
63+
--structthreshold 0
64+
--swiftversion 5.10
65+
--tabwidth unspecified
66+
--throwcapturing
67+
--trailingclosures
68+
--trimwhitespace nonblank-lines
69+
--typeattributes preserve
70+
--typeblanklines remove
71+
--typemark "MARK: - %t"
72+
--varattributes preserve
73+
--voidtype void
74+
--wraparguments preserve
75+
--wrapcollections preserve
76+
--wrapconditions preserve
77+
--wrapeffects preserve
78+
--wrapenumcases always
79+
--wrapparameters default
80+
--wrapreturntype preserve
81+
--wrapternary default
82+
--wraptypealiases preserve
83+
--xcodeindentation disabled
84+
--yodaswap always
85+
--disable blankLineAfterImports,wrapMultilineStatementBraces
86+
--enable acronyms,blankLinesBetweenImports

Sources/OpenSwiftUI/Core/Data/VersionSeed.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ struct VersionSeed: CustomStringConvertible {
4747
newValue.merge(seed)
4848
return newValue
4949
}
50+
51+
@inline(__always)
52+
static func == (lhs: VersionSeed, rhs: VersionSeed) -> Bool {
53+
lhs.value == rhs.value
54+
}
55+
56+
@inline(__always)
57+
static func != (lhs: VersionSeed, rhs: VersionSeed) -> Bool {
58+
lhs.value != rhs.value
59+
}
5060
}
5161

5262
private func merge32(_ a: UInt32, _ b: UInt32) -> UInt32 {

Sources/OpenSwiftUI/Core/Graph/GraphHost.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GraphHost {
1717

1818
private(set) var data: Data
1919
private(set) var isInstantiated = false
20-
private(set) var hostPreferenceValues: OptionalAttribute<PreferenceList>
20+
/* private(set)*/ var hostPreferenceValues: OptionalAttribute<PreferenceList>
2121
private(set) var lastHostPreferencesSeed: VersionSeed = .invalid
2222
private var pendingTransactions: [AsyncTransaction] = []
2323
/*private(set)*/ var inTransaction = false
@@ -147,16 +147,33 @@ class GraphHost {
147147
}
148148

149149
final func preferenceValue<Key: HostPreferenceKey>(_ key: Key.Type) -> Key.Value {
150-
fatalError("TODO")
150+
if data.hostPreferenceKeys.contains(key) {
151+
return preferenceValues()[key].value
152+
} else {
153+
defer { removePreference(key) }
154+
addPreference(key)
155+
return preferenceValues()[key].value
156+
}
151157
}
152-
158+
153159
final func addPreference<Key: HostPreferenceKey>(_ key: Key.Type) {
154-
fatalError("TODO")
160+
OGGraph.withoutUpdate {
161+
data.hostPreferenceKeys.add(key)
162+
}
155163
}
156-
164+
165+
final func removePreference<Key: HostPreferenceKey>(_ key: Key.Type) {
166+
OGGraph.withoutUpdate {
167+
data.hostPreferenceKeys.remove(key)
168+
}
169+
}
170+
157171
final func updatePreferences() -> Bool {
158-
// fatalError("TODO")
159-
return false
172+
let seed = hostPreferenceValues.value?.mergedSeed ?? .empty
173+
let lastSeed = lastHostPreferencesSeed
174+
let didUpdate = seed.isInvalid || lastSeed.isInvalid || (seed != lastSeed)
175+
lastHostPreferencesSeed = seed
176+
return didUpdate
160177
}
161178

162179
final func updateRemovedState() {
@@ -203,11 +220,11 @@ class GraphHost {
203220
}
204221
}
205222

206-
final func uninstantiate(immediately: Bool) {
223+
final func uninstantiate(immediately _: Bool) {
207224
guard isInstantiated else {
208225
return
209226
}
210-
// TODO
227+
// TODO:
211228
}
212229

213230
final func graphInvalidation(from attribute: OGAttribute?) {
@@ -224,7 +241,7 @@ class GraphHost {
224241
} else {
225242
asyncTransaction(
226243
transaction,
227-
mutation: EmptyGraphMutation(),
244+
mutation: EmptyGraphMutation(),
228245
style: ._1,
229246
mayDeferUpdate: true
230247
)
@@ -264,7 +281,7 @@ class GraphHost {
264281

265282
final func continueTransaction(_ body: @escaping () -> Void) {
266283
var host = self
267-
while(!host.inTransaction) {
284+
while !host.inTransaction {
268285
guard let parent = host.parentHost else {
269286
asyncTransaction(
270287
Transaction(),
@@ -349,7 +366,7 @@ private final class AsyncTransaction {
349366
func append<Mutation: GraphMutation>(_ mutation: Mutation) {
350367
// ``GraphMutation/combine`` is mutating function
351368
// So we use ``Array.subscript/_modify`` instead of ``Array.last/getter`` to mutate inline
352-
if !mutations.isEmpty, mutations[mutations.count-1].combine(with: mutation) {
369+
if !mutations.isEmpty, mutations[mutations.count - 1].combine(with: mutation) {
353370
return
354371
}
355372
mutations.append(mutation)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ViewBuilder.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2023
6+
// Status: WIP
7+
8+
struct _SafeAreaInsetsModifier: PrimitiveViewModifier/*, MultiViewModifier*/ {
9+
var elements: [SafeAreaInsets.Element]
10+
var nextInsets: SafeAreaInsets.OptionalValue?
11+
12+
var insets: EdgeInsets = .init() // FIXME
13+
}

Sources/OpenSwiftUI/Core/View/TODO/_ViewInputs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public struct _ViewInputs {
77
var position: Attribute<ViewOrigin>
88
var containerPosition: Attribute<ViewOrigin>
99
var size: Attribute<ViewSize>
10-
// var safeAreaInsets: OptionalAttribute<SafeAreaInsets>
10+
var safeAreaInsets: OptionalAttribute<SafeAreaInsets>
1111
}

0 commit comments

Comments
 (0)