Skip to content

Commit

Permalink
Fix linux platform build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Jan 12, 2025
1 parent 0042d24 commit 26da72b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,48 @@
// Audited for iOS 18.0
// Status: Complete

#if canImport(Darwin)

#if canImport(CoreGraphics)
package import CoreGraphics
#else
package import Foundation
// FIXME: Use Silica or other implementation
public struct CGAffineTransform: Equatable {
public init() {
a = .zero
b = .zero
c = .zero
d = .zero
tx = .zero
ty = .zero
}

public init(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double) {
self.a = a
self.b = b
self.c = c
self.d = d
self.tx = tx
self.ty = ty
}

public var a: Double
public var b: Double
public var c: Double
public var d: Double
public var tx: Double
public var ty: Double

public static let identity = CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0)

public func concatenating(_ transform: CGAffineTransform) -> CGAffineTransform {
preconditionFailure("Unimplemented")
}

public func inverted() -> CGAffineTransform {
preconditionFailure("Unimplemented")
}
}
#endif

extension CGAffineTransform {
package init(rotation: Angle) {
Expand Down Expand Up @@ -78,5 +117,3 @@ extension CGAffineTransform: ProtobufMessage {
self = transform
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,6 @@
public import Foundation
#if canImport(QuartzCore)
public import QuartzCore
#else
// FIXME: Use Silica or other implementation
public struct CGAffineTransform {
public init()

public init(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double)

public var a: Double

public var b: Double

public var c: Double

public var d: Double

public var tx: Double

public var ty: Double
}
#endif

@frozen
Expand Down Expand Up @@ -200,7 +181,6 @@ extension CGPoint {
}
}

#if canImport(QuartzCore)
extension CGAffineTransform {
package init(_ m: ProjectionTransform) {
self.init(
Expand All @@ -211,6 +191,7 @@ extension CGAffineTransform {
}
}

#if canImport(QuartzCore)
extension CATransform3D {
package init(_ m: ProjectionTransform) {
self.init(
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUICore/Layout/View/ViewTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,12 @@ extension [CGPoint]: ApplyViewTransform, ViewTransformable {
case let .translation(offset):
self = map { $0 + offset }
case let .affineTransform(matrix, inverse):
#if canImport(CoreGraphics)
let tranform = inverse ? matrix.inverted() : matrix
self = map { $0.applying(tranform) }
#else
preconditionFailure("CGAffineTransform+applying is not available on this platform")
#endif
case let .projectionTransform(matrix, inverse):
apply(matrix, inverse: inverse)
case .coordinateSpace, .sizedSpace, .scrollGeometry:
Expand Down
16 changes: 16 additions & 0 deletions Tests/OpenSwiftUICoreTests/Layout/View/ViewTransformTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct ViewTransformTests {

@Test
func viewTransformDescription() {
#if canImport(CoreGraphics)
var transform = ViewTransform()
transform.appendTranslation(CGSize(width: 10, height: 10))
#expect(transform.description == #"""
Expand All @@ -61,5 +62,20 @@ struct ViewTransformTests {
#expect(transform.description == #"""
((10.0, 10.0), CoordinateSpaceElement(name: AnyHashable("a"))); SizedSpaceElement(name: AnyHashable("b"), size: (20.0, 20.0))
"""#)
#else
var transform = ViewTransform()
transform.appendTranslation(CGSize(width: 10, height: 10))
#expect(transform.description == #"""
CGSize(width: 10.0, height: 10.0)
"""#)
transform.appendCoordinateSpace(name: "a")
#expect(transform.description == #"""
(CGSize(width: 10.0, height: 10.0), CoordinateSpaceElement(name: AnyHashable("a")))
"""#)
transform.appendSizedSpace(name: "b", size: .init(width: 20, height: 20))
#expect(transform.description == #"""
(CGSize(width: 10.0, height: 10.0), CoordinateSpaceElement(name: AnyHashable("a"))); SizedSpaceElement(name: AnyHashable("b"), size: Foundation.CGSize(width: 20.0, height: 20.0))
"""#)
#endif
}
}

0 comments on commit 26da72b

Please sign in to comment.