Skip to content

Commit

Permalink
Update ViewGraph implementation (#58)
Browse files Browse the repository at this point in the history
* Update GraphHost preference

* Update EmptyView

* Add LayoutDirection implementation

* Add SafeAreaInsets API

* Add RootGeometry

* Update ViewGraph instantiateOutputs

* Fix Linux build issue
  • Loading branch information
Kyle-Ye committed Apr 4, 2024
1 parent 831c079 commit 14597bb
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 33 deletions.
86 changes: 86 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
--acronyms ID,URL,UUID
--allman false
--anonymousforeach convert
--assetliterals visual-width
--asynccapturing
--beforemarks
--binarygrouping 4,8
--categorymark "MARK: %c"
--classthreshold 0
--closingparen balanced
--closurevoid remove
--commas always
--conflictmarkers reject
--decimalgrouping 3,6
--elseposition same-line
--emptybraces no-space
--enumnamespaces always
--enumthreshold 0
--exponentcase lowercase
--exponentgrouping disabled
--extensionacl on-declarations
--extensionlength 0
--extensionmark "MARK: - %t + %c"
--fractiongrouping disabled
--fragment false
--funcattributes preserve
--generictypes
--groupedextension "MARK: %c"
--guardelse auto
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef no-indent
--importgrouping alpha
--indent 4
--indentcase false
--indentstrings false
--lifecycle
--lineaftermarks true
--linebreaks lf
--markcategories true
--markextensions always
--marktypes always
--maxwidth none
--modifierorder
--nevertrailing
--nospaceoperators
--nowrapoperators
--octalgrouping 4,8
--onelineforeach ignore
--operatorfunc spaced
--organizetypes actor,class,enum,struct
--patternlet hoist
--ranges spaced
--redundanttype inferred
--self remove
--selfrequired
--semicolons inline
--shortoptionals always
--smarttabs enabled
--someany false
--stripunusedargs always
--structthreshold 0
--swiftversion 5.10
--tabwidth unspecified
--throwcapturing
--trailingclosures
--trimwhitespace nonblank-lines
--typeattributes preserve
--typeblanklines remove
--typemark "MARK: - %t"
--varattributes preserve
--voidtype void
--wraparguments preserve
--wrapcollections preserve
--wrapconditions preserve
--wrapeffects preserve
--wrapenumcases always
--wrapparameters default
--wrapreturntype preserve
--wrapternary default
--wraptypealiases preserve
--xcodeindentation disabled
--yodaswap always
--disable blankLineAfterImports,wrapMultilineStatementBraces
--enable acronyms,blankLinesBetweenImports
10 changes: 10 additions & 0 deletions Sources/OpenSwiftUI/Core/Data/VersionSeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ struct VersionSeed: CustomStringConvertible {
newValue.merge(seed)
return newValue
}

@inline(__always)
static func == (lhs: VersionSeed, rhs: VersionSeed) -> Bool {
lhs.value == rhs.value
}

@inline(__always)
static func != (lhs: VersionSeed, rhs: VersionSeed) -> Bool {
lhs.value != rhs.value
}
}

private func merge32(_ a: UInt32, _ b: UInt32) -> UInt32 {
Expand Down
41 changes: 29 additions & 12 deletions Sources/OpenSwiftUI/Core/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GraphHost {

private(set) var data: Data
private(set) var isInstantiated = false
private(set) var hostPreferenceValues: OptionalAttribute<PreferenceList>
/* private(set)*/ var hostPreferenceValues: OptionalAttribute<PreferenceList>
private(set) var lastHostPreferencesSeed: VersionSeed = .invalid
private var pendingTransactions: [AsyncTransaction] = []
/*private(set)*/ var inTransaction = false
Expand Down Expand Up @@ -147,16 +147,33 @@ class GraphHost {
}

final func preferenceValue<Key: HostPreferenceKey>(_ key: Key.Type) -> Key.Value {
fatalError("TODO")
if data.hostPreferenceKeys.contains(key) {
return preferenceValues()[key].value
} else {
defer { removePreference(key) }
addPreference(key)
return preferenceValues()[key].value
}
}

final func addPreference<Key: HostPreferenceKey>(_ key: Key.Type) {
fatalError("TODO")
OGGraph.withoutUpdate {
data.hostPreferenceKeys.add(key)
}
}


final func removePreference<Key: HostPreferenceKey>(_ key: Key.Type) {
OGGraph.withoutUpdate {
data.hostPreferenceKeys.remove(key)
}
}

final func updatePreferences() -> Bool {
// fatalError("TODO")
return false
let seed = hostPreferenceValues.value?.mergedSeed ?? .empty
let lastSeed = lastHostPreferencesSeed
let didUpdate = seed.isInvalid || lastSeed.isInvalid || (seed != lastSeed)
lastHostPreferencesSeed = seed
return didUpdate
}

final func updateRemovedState() {
Expand Down Expand Up @@ -203,11 +220,11 @@ class GraphHost {
}
}

final func uninstantiate(immediately: Bool) {
final func uninstantiate(immediately _: Bool) {
guard isInstantiated else {
return
}
// TODO
// TODO:
}

final func graphInvalidation(from attribute: OGAttribute?) {
Expand All @@ -224,7 +241,7 @@ class GraphHost {
} else {
asyncTransaction(
transaction,
mutation: EmptyGraphMutation(),
mutation: EmptyGraphMutation(),
style: ._1,
mayDeferUpdate: true
)
Expand Down Expand Up @@ -264,7 +281,7 @@ class GraphHost {

final func continueTransaction(_ body: @escaping () -> Void) {
var host = self
while(!host.inTransaction) {
while !host.inTransaction {
guard let parent = host.parentHost else {
asyncTransaction(
Transaction(),
Expand Down Expand Up @@ -349,7 +366,7 @@ private final class AsyncTransaction {
func append<Mutation: GraphMutation>(_ mutation: Mutation) {
// ``GraphMutation/combine`` is mutating function
// So we use ``Array.subscript/_modify`` instead of ``Array.last/getter`` to mutate inline
if !mutations.isEmpty, mutations[mutations.count-1].combine(with: mutation) {
if !mutations.isEmpty, mutations[mutations.count - 1].combine(with: mutation) {
return
}
mutations.append(mutation)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ViewBuilder.swift
// OpenSwiftUI
//
// Audited for RELEASE_2023
// Status: WIP

struct _SafeAreaInsetsModifier: PrimitiveViewModifier/*, MultiViewModifier*/ {
var elements: [SafeAreaInsets.Element]
var nextInsets: SafeAreaInsets.OptionalValue?

var insets: EdgeInsets = .init() // FIXME
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Core/View/TODO/_ViewInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public struct _ViewInputs {
var position: Attribute<ViewOrigin>
var containerPosition: Attribute<ViewOrigin>
var size: Attribute<ViewSize>
// var safeAreaInsets: OptionalAttribute<SafeAreaInsets>
var safeAreaInsets: OptionalAttribute<SafeAreaInsets>
}
Loading

0 comments on commit 14597bb

Please sign in to comment.