Skip to content

Commit

Permalink
1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Jun 14, 2024
1 parent a68ef1a commit ba7eb20
Show file tree
Hide file tree
Showing 22 changed files with 854 additions and 192 deletions.
2 changes: 1 addition & 1 deletion Sources/Engine/Sources/AnyAnimatableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AnyAnimatableDataStorageBase: @unchecked Sendable {
@usableFromInline
final class AnyAnimatableDataStorage<
Vector: VectorArithmetic
>: AnyAnimatableDataStorageBase {
>: AnyAnimatableDataStorageBase, @unchecked Sendable {

var vector: Vector

Expand Down
2 changes: 1 addition & 1 deletion Sources/Engine/Sources/AnyShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AnyShapeStorageBase: @unchecked Sendable {
}

@usableFromInline
final class AnyShapeStorage<S: Shape>: AnyShapeStorageBase {
final class AnyShapeStorage<S: Shape>: AnyShapeStorageBase, @unchecked Sendable {

var shape: S

Expand Down
26 changes: 15 additions & 11 deletions Sources/Engine/Sources/EnvironmentValuesVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ extension EnvironmentValues {

var ptr = plist.elements
while let p = ptr {
let typeName = _typeName(p.pointee.fields.keyType, qualified: false)
let typeName = _typeName(p.keyType, qualified: false)
if typeName == key {
guard
let environmentKey = swift_getStructGenerics(for: p.pointee.fields.keyType)?.first,
let environmentKey = swift_getStructGenerics(for: p.keyType)?.first,
let conformance = EnvironmentKeyProtocolDescriptor.conformance(of: environmentKey)
else {
return nil
}
EnvironmentKeyLookupCache.shared[key] = conformance
return conformance.value(in: self)
}
ptr = p.pointee.fields.after
ptr = p.after
}
return nil
}
Expand All @@ -113,7 +113,7 @@ extension EnvironmentValues {
fileprivate var plist: PropertyList {
guard let plistValue = try? swift_getFieldValue("_plist", Any.self, self)
else {
return PropertyList(elements: nil)
return PropertyList(ptr: nil)
}
func project<T>(_ value: T) -> PropertyList {
unsafeBitCast(value, to: PropertyList.self)
Expand All @@ -125,18 +125,22 @@ extension EnvironmentValues {

extension ProtocolConformance where P == EnvironmentKeyProtocolDescriptor {
fileprivate func value<Value>(in environment: EnvironmentValues) -> Value? {
var visitor = EnvironmentValuesVisitor(environment: environment)
var visitor = EnvironmentValuesVisitor<Value>(environment: environment)
visit(visitor: &visitor)
return visitor.output as? Value
return visitor.output
}
}

private struct EnvironmentValuesVisitor: EnvironmentKeyVisitor {
private struct EnvironmentValuesVisitor<Value>: EnvironmentKeyVisitor {
var environment: EnvironmentValues
var output: Any?
var output: Value!

mutating func visit<Key: EnvironmentKey>(type: Key.Type) {
output = environment[Key.self]
if Key.Value.self == Value.self {
output = environment[Key.self] as? Value
} else if MemoryLayout<Key.Value>.size == MemoryLayout<Value>.size {
output = unsafeBitCast(environment[Key.self], to: Value.self)
}
}
}

Expand Down Expand Up @@ -180,13 +184,13 @@ public struct _EnvironmentValuesLogModifier: ViewModifier {
var message = "\n=== EnvironmentValues ===\n"
var ptr = environment.plist.elements
while let p = ptr {
let keyType = _typeName(p.pointee.fields.keyType, qualified: false)
let keyType = _typeName(p.keyType, qualified: false)
let value = environment.visit(keyType, as: Any.self)
message += """
\(keyType)
▿ value: \(value ?? "nil")\n
"""
ptr = p.pointee.fields.after
ptr = p.after
}
return message
}()
Expand Down
9 changes: 8 additions & 1 deletion Sources/Engine/Sources/ForEachSubview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ public struct ForEachSubview<
_ source: VariadicView<Source>,
@ViewBuilder subview: @escaping (Int, Subview) -> Content
) where Subview == AnyVariadicView.Subview {
self.source = source.children.map { $0 }
self.init(source.children.map { $0 }, subview: subview)
}

public init(
_ source: [AnyVariadicView.Subview],
@ViewBuilder subview: @escaping (Int, Subview) -> Content
) where Subview == AnyVariadicView.Subview {
self.source = source
self.subview = subview
}

Expand Down
28 changes: 13 additions & 15 deletions Sources/Engine/Sources/GraphInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ extension _GraphInputs {
key: String,
_: Value.Type
) -> Value? {
customInputs.withUnsafeValuePointer(key: key, as: Value.self) { ptr in
ptr.pointee.value
}
customInputs.value(key: key, as: Value.self)
}
}

Expand Down Expand Up @@ -112,7 +110,7 @@ extension PropertyList {
fileprivate mutating func detach() {
var ptr = elements
while let p = ptr {
let key = _typeName(ptr!.pointee.fields.keyType, qualified: true)
let key = _typeName(ptr!.keyType, qualified: true)
var isMatch = key.hasSuffix(".MatchedGeometryScope")
#if !os(macOS)
let branchKey: String
Expand All @@ -126,38 +124,38 @@ extension PropertyList {
if isMatch {
// Reached the {UI/NS}ViewRepresentable
#if !os(macOS)
if let next = p.pointee.fields.after {
if let next = p.after {
// Reached the UIViewRepresentable
if _typeName(next.pointee.fields.keyType, qualified: true).hasSuffix(branchKey) {
if _typeName(next.keyType, qualified: true).hasSuffix(branchKey) {
ptr = next
}
}
#endif
break
}
if let next = p.pointee.fields.after {
if let next = p.after {
ptr = next
} else {
return
}
}

let tail = ptr!
var last = tail.pointee.fields.after
tail.pointee.fields.after = nil
while let p = last?.pointee.fields.after {
var last = tail.after
tail.after = nil
while let p = last?.after {
last = p
}

ptr = elements
let offset = tail.pointee.fields.length - (last == nil ? 1 : 2)
let offset = tail.length - (last == nil ? 1 : 2)
while offset > 0, let p = ptr {
p.pointee.fields.length -= offset
ptr = p.pointee.fields.after
p.length -= offset
ptr = p.after
}
if let last {
_ = Unmanaged<AnyObject>.fromOpaque(last).retain() // Prevent dealloc
tail.pointee.fields.after = last
_ = last.object.retain() // Prevent dealloc
tail.after = last
}
}
}
59 changes: 59 additions & 0 deletions Sources/Engine/Sources/Group.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Copyright (c) Nathan Tannar
//

import SwiftUI

extension Group where Content: View {

@available(iOS, introduced: 13.0, deprecated: 100000.0, message: "Please use the built in Group(subviewsOf: ...) init")
@available(macOS, introduced: 10.15, deprecated: 100000.0, message: "Please use the built in Group(subviewsOf: ...) init")
@available(tvOS, introduced: 13.0, deprecated: 100000.0, message: "Please use the built in Group(subviewsOf: ...) init")
@available(watchOS, introduced: 6.0, deprecated: 100000.0, message: "Please use the built in Group(subviewsOf: ...) init")
@available(visionOS, introduced: 1.0, deprecated: 100000.0, message: "Please use the built in Group(subviewsOf: ...) init")
public init<V: View, Result: View>(
subviewsOf view: V,
@ViewBuilder transform: @escaping (VariadicView<V>) -> Result
) where Content == VariadicViewAdapter<V, Result> {
self.init {
VariadicViewAdapter(source: view, content: transform)
}
}
}


// MARK: - Previews

struct Group_Previews: PreviewProvider {
static var previews: some View {
Group {
Group(subviewsOf: Content()) { source in
VStack {
HStack {
source[0]
source[1]
}

source[2...]
}
}
.previewDisplayName("subviewsOf")
}
}

struct Content: View {
var body: some View {
Section {
Text("Line 1")
Text("Line 2")
Text("Line 3")
Text("Line 4")
Text("Line 5")
} header: {
Text("Header")
} footer: {
Text("Footer")
}
}
}
}
Loading

0 comments on commit ba7eb20

Please sign in to comment.