Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Jun 13, 2024
1 parent 52f22b9 commit 9420e40
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/nathantannar4/Engine", from: "1.5.1"),
.package(url: "https://github.com/nathantannar4/Engine", from: "1.8.0"),
],
targets: [
.target(
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ let package = Package(
)
```

### Xcode Cloud / Github Actions / Fastlane / CI

[Engine](https://github.com/nathantannar4/Engine) includes a Swift macro, which requires user validation to enable or the build will fail. When configuring your CI, pass the flag `-skipMacroValidation` to `xcodebuild` to fix this.

## Introduction to Turbocharger

`Turbocharger` was started with the two goals. 1) To expand the standard API that SwiftUI provides to what many would commonly desired or need; and 2) To demonstrate how to use [Engine](https://github.com/nathantannar4/Engine) to make reusable components that are backwards compatible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,16 @@ extension AttributeContainer {
#endif
}

#if hasAttribute(retroactive)
extension NSParagraphStyle: @unchecked @retroactive Sendable { }

#if os(macOS)
extension NSFont: @unchecked @retroactive Sendable { }
#endif
#else
extension NSParagraphStyle: @unchecked Sendable { }

#if os(macOS)
extension NSFont: @unchecked Sendable { }
#endif
#endif
12 changes: 8 additions & 4 deletions Sources/Turbocharger/Sources/Extensions/Text+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Text {
/// string keys if necessary.
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public func resolveAttributed(in environment: EnvironmentValues) -> AttributedString {
guard MemoryLayout<Text>.size == MemoryLayout<Text.Layout>.size else {
guard MemoryLayout<Text>.size == MemoryLayout<Text.TypeLayout>.size else {
return AttributedString(resolve(in: environment))
}
return _resolveAttributed(in: environment)
Expand Down Expand Up @@ -100,13 +100,13 @@ extension Text {
}
}

private struct Layout {
private struct TypeLayout {
var storage: Storage
var modifiers: [Modifier]
}

private var layout: Text.Layout {
unsafeBitCast(self, to: Text.Layout.self)
private var layout: Text.TypeLayout {
unsafeBitCast(self, to: Text.TypeLayout.self)
}

func _resolveAttributed(in environment: EnvironmentValues) -> AttributedString {
Expand Down Expand Up @@ -220,5 +220,9 @@ extension Text {
}

#if os(iOS) || os(tvOS) || os(watchOS)
#if hasAttribute(retroactive)
extension NSTextAttachment: @unchecked @retroactive Sendable { }
#else
extension NSTextAttachment: @unchecked Sendable { }
#endif
#endif
9 changes: 5 additions & 4 deletions Sources/Turbocharger/Sources/View/CALayerRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Engine
/// SwiftUI view hierarchy.
@available(iOS 14.0, macOS 11.0, tvOS 14.0, *)
@available(watchOS, unavailable)
@MainActor @preconcurrency
public protocol CALayerRepresentable: View where Body == Never {
associatedtype CALayerType: CALayer

Expand All @@ -22,20 +23,20 @@ public protocol CALayerRepresentable: View where Body == Never {
/// system calls the ``CALayerRepresentable/updateCALayer(_:context:)``
/// method.
///
@MainActor(unsafe) func makeCALayer(_ layer: CALayerType, context: Context)
@MainActor @preconcurrency func makeCALayer(_ layer: CALayerType, context: Context)

/// Updates the layer with new information.
///
/// > Note: This protocol implementation is optional
///
@MainActor(unsafe) func updateCALayer(_ layer: CALayerType, context: Context)
@MainActor @preconcurrency func updateCALayer(_ layer: CALayerType, context: Context)

associatedtype Coordinator = Void

@MainActor(unsafe) func makeCoordinator() -> Coordinator
@MainActor @preconcurrency func makeCoordinator() -> Coordinator

/// Cleans up the layer in anticipation of it's removal.
@MainActor(unsafe) static func dismantleCALayer(_ layer: CALayerType, coordinator: Coordinator)
@MainActor @preconcurrency static func dismantleCALayer(_ layer: CALayerType, coordinator: Coordinator)

typealias Context = CALayerRepresentableContext<Self>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Engine

/// A protocol for defining a `NSViewRepresentable`/`UIViewRepresentable`
/// that has a backwards compatible `sizeThatFits`
@MainActor @preconcurrency
public protocol PlatformViewRepresentable: DynamicProperty, View where Body == Never {

#if os(macOS)
Expand All @@ -17,13 +18,13 @@ public protocol PlatformViewRepresentable: DynamicProperty, View where Body == N
associatedtype PlatformView: UIView
#endif

@MainActor(unsafe) func makeView(context: Context) -> PlatformView
@MainActor(unsafe) func updateView(_ view: PlatformView, context: Context)
@MainActor(unsafe) func sizeThatFits(_ proposal: ProposedSize, view: PlatformView) -> CGSize?
@MainActor(unsafe) static func dismantleView(_ view: PlatformView, coordinator: Coordinator)
@MainActor @preconcurrency func makeView(context: Context) -> PlatformView
@MainActor @preconcurrency func updateView(_ view: PlatformView, context: Context)
@MainActor @preconcurrency func sizeThatFits(_ proposal: ProposedSize, view: PlatformView) -> CGSize?
@MainActor @preconcurrency static func dismantleView(_ view: PlatformView, coordinator: Coordinator)

associatedtype Coordinator = Void
@MainActor(unsafe) func makeCoordinator() -> Coordinator
@MainActor @preconcurrency func makeCoordinator() -> Coordinator

typealias Context = _PlatformViewRepresentableBody<Self>.Context
}
Expand Down

1 comment on commit 9420e40

@danqing
Copy link

Choose a reason for hiding this comment

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

@nathantannar4 if 1.3.0 is ready for use it'd be great if you can cut a release! There doesn't seem to be an Engine 1.8.0 — not sure if you are still working on that. Thank you!

Please sign in to comment.