Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 support #118

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"originHash" : "d9e897732f60af4412110707787651b74e68d6f3e1b560c546e4b10fc8f816e7",
"pins" : [
{
"identity" : "descriptors",
"kind" : "remoteSourceControl",
"location" : "https://github.com/FluidGroup/Descriptors",
"location" : "https://github.com/ntnmrndn/Descriptors",
"state" : {
"revision" : "174dbbaff40b455614b62ea3ed16771adde25e65",
"version" : "0.2.2"
"branch" : "antoine/swift6",
"revision" : "8f0c6b119cb15e09155460576773f1151c96ce62"
}
},
{
"identity" : "texture",
"kind" : "remoteSourceControl",
"location" : "https://github.com/FluidGroup/Texture.git",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on a texture update, to revert later.

"location" : "https://github.com/ntnmrndn/Texture.git",
"state" : {
"revision" : "68df47f0d26522da76b06f22e9a97e4d4ab58dad",
"version" : "3.0.2"
"branch" : "antoine/swift6",
"revision" : "2c945a0641d39628f06d21ef7b7f4fb64119812f"
}
}
],
"version" : 2
"version" : 3
}
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:6.0
import PackageDescription

let package = Package(
Expand All @@ -10,18 +10,18 @@ let package = Package(
.library(name: "TextureSwiftSupport", targets: ["TextureSwiftSupport"]),
],
dependencies: [
.package(url: "https://github.com/FluidGroup/Texture.git", from: "3.0.2"),
.package(url: "https://github.com/FluidGroup/Descriptors", from: "0.2.0"),
.package(url: "https://github.com/ntnmrndn/Texture.git", branch: "antoine/swift6"),
.package(url: "https://github.com/ntnmrndn/Descriptors", branch: "antoine/swift6"),
],
targets: [
.target(
name: "TextureSwiftSupport",
name: "TextureSwiftSupport",
dependencies: [
.product(name: "AsyncDisplayKit", package: "Texture"),
.product(name: "Descriptors", package: "Descriptors")
],
path: "Sources"
),
],
swiftLanguageVersions: [.v5]
swiftLanguageModes: [.v6]
)
2 changes: 1 addition & 1 deletion Sources/Components/Compositions/AnyDisplayNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ open class AnyDisplayNode: SafeAreaDisplayNode {
}

@available(*, unavailable)
open override func onDidLoad(_ body: @escaping ASDisplayNodeDidLoadBlock) {
open override func onDidLoad(_ body: @escaping ASDisplayNodeDidLoadBlock) {
super.onDidLoad(body)
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Components/Compositions/HighlightCellNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ open class HighlightCellNode<D: ASDisplayNode>: NamedDisplayCellNodeBase {
}
}

@MainActor
open override var isHighlighted: Bool {
didSet {
highlightHandler?(isHighlighted, self.view, animationTargetNode.view)
Expand Down
1 change: 1 addition & 0 deletions Sources/Components/Compositions/InteractiveNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ open class InteractiveNode<D: ASDisplayNode>: NamedDisplayControlNodeBase {
}
}

@MainActor
open override var isHighlighted: Bool {
didSet {
highlightHandler?(isHighlighted, self.view, animationTargetNode.view)
Expand Down
25 changes: 18 additions & 7 deletions Sources/Components/Compositions/OnAppearNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ public final class OnAppearNode<Content: ASDisplayNode>: NamedDisplayCellNodeBas

state = .init()

bottomRightTiledLayerNode = .init(wrappedView: { .init() })
topLeftTiledLayerNode = .init(wrappedView: { .init() })

bottomRightTiledLayerNode = .init(wrappedView: {
.init()
})
topLeftTiledLayerNode = .init(wrappedView: {
.init()
})

setNeedsLayout()

bottomRightTiledLayerNode!.wrappedView.setOnDraw { [weak self] in
Expand Down Expand Up @@ -214,24 +218,31 @@ private final class TiledLayerView: UIView {
return view
}

func setOnDraw(_ closure: @escaping @MainActor () -> Void) {
func setOnDraw(_ closure: @Sendable @escaping @MainActor () -> Void) {
(layer as! TiledLayer).onDraw = closure
}
}

private final class TiledLayer: CATiledLayer {

var onDraw: () -> Void = {}
var onDraw: @MainActor @Sendable () -> Void = {}

override class func fadeDuration() -> CFTimeInterval {
0
}

override func draw(in ctx: CGContext) {
let onDraw = self.onDraw
if Thread.isMainThread {
onDraw()
MainActor.assumeIsolated {
onDraw()
}
} else {
DispatchQueue.main.async(execute: onDraw)
DispatchQueue.main.async(execute: {
MainActor.assumeIsolated {
onDraw()
}
})
}
}
}
112 changes: 68 additions & 44 deletions Sources/Components/Compositions/ShapeLayerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fileprivate final class BackingShapeLayerNode : ASDisplayNode {
}

/// A node that displays shape with CAShapeLayer
public final class ShapeLayerNode : ASDisplayNode, ShapeDisplaying {
public final class ShapeLayerNode : ASDisplayNode, MainActorShapeDisplaying, @unchecked Sendable {

private let backingNode = BackingShapeLayerNode()

private let updateClosure: Update
Expand All @@ -38,54 +38,87 @@ public final class ShapeLayerNode : ASDisplayNode, ShapeDisplaying {
}
}

public init(update: @escaping Update) {
self.updateClosure = update
super.init()
backgroundColor = .clear
backingNode.backgroundColor = .clear
backingNode.isLayerBacked = true
automaticallyManagesSubnodes = true
}

/// Warning: shape\* values will actually be set at didLoad
public convenience init (
update: @escaping Update,
shapeFillColor: UIColor = .clear,
shapeStrokeColor: UIColor = .clear,
shapeLineWidth: CGFloat = 0.0
) {
self.init(update: update)
backgroundColor = .clear
backingNode.backgroundColor = .clear
backingNode.isLayerBacked = true
automaticallyManagesSubnodes = true
self.onDidLoad({
let shapeLayerNode = ($0 as! ShapeLayerNode)
shapeLayerNode.shapeFillColor = shapeFillColor
shapeLayerNode.shapeStrokeColor = shapeStrokeColor
shapeLayerNode.shapeLineWidth = shapeLineWidth
})
}

public override var supportsLayerBacking: Bool {
return true
}

public var shapeLayer: CAShapeLayer {

@MainActor
/// Beware, direct access to lineWidth is not supported here when using usesInnerBorder, otherwise access should be safe
public var unsafeShapeLayer: CAShapeLayer {
backingNode.layer
}

// To be thread-safe, using stored property

/// cache value for bg thread access
private var _shapeLineWidth: CGFloat = .zero

@MainActor
public var shapeLineWidth: CGFloat = 0 {
didSet {
_shapeLineWidth = shapeLineWidth
backingNode.layer.lineWidth = shapeLineWidth
setNeedsLayout()
}
}


@MainActor
public var shapeStrokeColor: UIColor? {
get {
return backingNode.layer.strokeColor.map { UIColor(cgColor: $0) }
}
set {
ASPerformBlockOnMainThread {
CATransaction.begin()
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
}
self.backingNode.layer.strokeColor = newValue?.cgColor
CATransaction.begin()
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
}
self.backingNode.layer.strokeColor = newValue?.cgColor
}
}


@MainActor
public var shapeFillColor: UIColor? {
get {
return backingNode.layer.fillColor.map { UIColor(cgColor: $0) }
}
set {
ASPerformBlockOnMainThread {
CATransaction.begin()
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
}
self.backingNode.layer.fillColor = newValue?.cgColor
CATransaction.begin()
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
}
self.backingNode.layer.fillColor = newValue?.cgColor
}
}

public override func layout() {
super.layout()
CATransaction.begin()
Expand All @@ -95,41 +128,32 @@ public final class ShapeLayerNode : ASDisplayNode, ShapeDisplaying {
}
backingNode.layer.path = updateClosure(backingNode.bounds).cgPath
}

public override var frame: CGRect {
didSet {
ASPerformBlockOnMainThread {
CATransaction.begin()
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
MainActor.assumeIsolated {
CATransaction.begin()
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
}
self.backingNode.layer.path = self.updateClosure(self.backingNode.bounds).cgPath
}
self.backingNode.layer.path = self.updateClosure(self.backingNode.bounds).cgPath
}
}
}

public init(
update: @escaping Update
) {
self.updateClosure = update
super.init()
backgroundColor = .clear
backingNode.backgroundColor = .clear
backingNode.isLayerBacked = true
automaticallyManagesSubnodes = true
}

public override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {

if usesInnerBorder {
return ASWrapperLayoutSpec(
layoutElement: ASInsetLayoutSpec(
insets: .init(
top: shapeLineWidth / 2,
left: shapeLineWidth / 2,
bottom: shapeLineWidth / 2,
right: shapeLineWidth / 2
top: _shapeLineWidth / 2,
left: _shapeLineWidth / 2,
bottom: _shapeLineWidth / 2,
right: _shapeLineWidth / 2
),
child: backingNode
)
Expand Down
Loading