Skip to content

Commit

Permalink
1.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Sep 27, 2024
1 parent 6d7ba80 commit 3eae8f6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 34 deletions.
21 changes: 15 additions & 6 deletions Sources/Engine/Sources/GraphInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ public struct _ViewInputsBridgeModifier: ViewModifier {

extension PropertyList {
fileprivate mutating func detach() {

var ptr = elements
var hasMatchedGeometryScope = false
var hasRoot = false
let rootInputSuffix = ".BodyInput<SwiftUI._ViewModifier_Content<SwiftUI.RootModifier>>"
while let p = ptr {
let key = _typeName(p.keyType, qualified: true)
var isMatch = key.hasSuffix(".MatchedGeometryScope")
var isMatch = key.hasSuffix(rootInputSuffix)
if isMatch {
hasMatchedGeometryScope = true
hasRoot = true
}
#if !os(macOS)
let branchKey: String
Expand Down Expand Up @@ -147,10 +149,13 @@ extension PropertyList {
let tail = ptr!
var last = tail.after
tail.after = nil
tail.skip = nil
tail.skipCount = 1
while let p = last?.after {
if !hasMatchedGeometryScope {
let key = _typeName(p.keyType, qualified: true)
if key.hasSuffix(".MatchedGeometryScope") {
if !hasRoot, let after = p.after {
let key = _typeName(after.keyType, qualified: true)
let isMatch = key.hasSuffix(rootInputSuffix) || key.hasSuffix(".ViewListOptionsInput")
if isMatch {
break
}
}
Expand All @@ -161,6 +166,10 @@ extension PropertyList {
let offset = tail.length - ((last?.length ?? 0) + 1)
while offset > 0, let p = ptr {
p.length -= offset
if let skip = p.skip, skip.length >= p.length {
p.skip = nil
p.skipCount = 1
}
ptr = p.after
}
if let last {
Expand Down
50 changes: 50 additions & 0 deletions Sources/Engine/Sources/PropertyList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ struct PropertyList {
}
}

var id: Int {
switch self {
case .v1(let ptr): ptr.pointee.fields.id
case .v6(let ptr): ptr.pointee.fields.id
}
}

var keyType: Any.Type {
switch self {
case .v1(let ptr): ptr.pointee.fields.keyType
Expand Down Expand Up @@ -109,6 +116,49 @@ struct PropertyList {
}
}

var skip: ElementPointer? {
get {
switch self {
case .v1:
return nil
case .v6(let ptr):
guard let skip = ptr.pointee.fields.skip else { return nil }
return .v6(skip)
}
}
nonmutating set {
switch self {
case .v1:
break
case .v6(let ptr):
if case .v6(let ptr) = newValue {
ptr.pointee.fields.skip = ptr
} else {
ptr.pointee.fields.skip = nil
}
}
}
}

var skipCount: UInt32 {
get {
switch self {
case .v1:
return 0
case .v6(let ptr):
return ptr.pointee.fields.skipCount
}
}
nonmutating set {
switch self {
case .v1:
break
case .v6(let ptr):
ptr.pointee.fields.skipCount = newValue
}
}
}

var length: UInt32 {
get {
switch self {
Expand Down
32 changes: 14 additions & 18 deletions Sources/Engine/Sources/ViewInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,21 @@ public struct _ViewInputsLogModifier: ViewInputsModifier {

public static func makeInputs(inputs: inout ViewInputs) {
#if DEBUG
let log: String = {
var message = "\n=== ViewInputs ===\n"
dump(inputs.options, to: &message)
var ptr = inputs._graphInputs.customInputs.elements
while let p = ptr {
dump(p, to: &message)
dump(p.fields, to: &message)
if let valueType = swift_getClassGenerics(for: p.metadata.0)?.first {
func project<Value>(_: Value.Type) {
let value = p.getValue(Value.self)
dump(value, to: &message)
}
_openExistential(valueType, do: project)
}
ptr = p.after
var message = ""
dump(inputs.options, to: &message)
os_log(.debug, "%@", message)
var ptr = inputs._graphInputs.customInputs.elements
while let p = ptr {
message = ""
dump(p, to: &message)
dump(p.fields, to: &message)
if let valueType = swift_getClassGenerics(for: p.metadata.0)?.first {
dump(valueType, to: &message)
}
return message
}()
os_log(.debug, "%@", log)
ptr = p.after

os_log(.debug, "%@", message)
}
#endif
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/EngineCore/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

import Foundation

@inline(__always)
public func isOpaqueViewAnyView() -> Bool {
// SwiftUI v6 wraps in AnyView
#if DEBUG && canImport(SwiftUICore)
return true
#else
return false
#endif
}

public struct MetadataField {
public let key: String
public let type: Any.Type
Expand Down
12 changes: 10 additions & 2 deletions Sources/EngineTests/EngineCoreMultiViewVisitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,22 @@ final class MultiViewVisitorTests: XCTestCase {
expectation(Text.self, count: 2) {
CustomMultiView()
} validation: { ctx, index in
XCTAssertEqual(ctx.id, .init(CustomMultiView.self).appending(TupleView<(Text, Text)>.self).appending(offset: index).appending(Text.self))
if isOpaqueViewAnyView() {
XCTAssertEqual(ctx.id, .init(CustomMultiView.self).appending(AnyView.self).appending(TupleView<(Text, Text)>.self).appending(offset: index).appending(Text.self))
} else {
XCTAssertEqual(ctx.id, .init(CustomMultiView.self).appending(TupleView<(Text, Text)>.self).appending(offset: index).appending(Text.self))
}
}
expectation(Text.self, count: 2) {
Group {
CustomMultiView()
}
} validation: { ctx, index in
XCTAssertEqual(ctx.id, .init(Group<CustomMultiView>.self).appending(CustomMultiView.self).appending(TupleView<(Text, Text)>.self).appending(offset: index).appending(Text.self))
if isOpaqueViewAnyView() {
XCTAssertEqual(ctx.id, .init(Group<CustomMultiView>.self).appending(CustomMultiView.self).appending(AnyView.self).appending(TupleView<(Text, Text)>.self).appending(offset: index).appending(Text.self))
} else {
XCTAssertEqual(ctx.id, .init(Group<CustomMultiView>.self).appending(CustomMultiView.self).appending(TupleView<(Text, Text)>.self).appending(offset: index).appending(Text.self))
}
}
}

Expand Down
9 changes: 1 addition & 8 deletions Sources/EngineTests/EngineCoreViewVisitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ final class ViewVisitorTests: XCTestCase {
}

func testOpaqueVisit() throws {
// SwiftUI v6 wraps in AnyView
var isAnyView = false
#if DEBUG
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) {
isAnyView = true
}
#endif
func makeContent() -> some View {
Text("Hello, World")
}
let content = makeContent()
if isAnyView {
if isOpaqueViewAnyView() {
var visitor = TestVisitor<AnyView>()
content.visit(visitor: &visitor)
XCTAssert(visitor.output)
Expand Down

0 comments on commit 3eae8f6

Please sign in to comment.