Skip to content

Commit

Permalink
Fix Sharing crash iOS 16 (#127)
Browse files Browse the repository at this point in the history
* Fix Sharing crash iOS 16

* Added threadsafe
  • Loading branch information
juicyfru1t authored Oct 21, 2024
1 parent 2ca2d75 commit 6c39a69
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions Sources/Addons/Sharing/Activity/SharingActivityManager.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
#if canImport(UIKit) && os(iOS)
import UIKit

@MainActor
internal final class SharingActivityManager<Activity: SharingCustomActivity>: UIActivity, Sendable {
internal final class SharingActivityManager<Activity: SharingCustomActivity>: UIActivity, @unchecked Sendable {

internal override class var activityCategory: UIActivity.Category {
Activity.category
}

private var items: [SharingItem] = []
private let accessQueue = DispatchQueue(
label: "SharingActivityManager \(UUID().uuidString)",
qos: .userInitiated,
attributes: .concurrent
)

private var _items: [SharingItem] = []
private var items: [SharingItem] {
get {
accessQueue.sync {
_items
}
}
set {
accessQueue.async(flags: .barrier) { [weak self] in
self?._items = newValue
}
}
}

internal let navigator: ScreenNavigator
internal let activity: Activity

internal override var activityType: UIActivity.ActivityType? {
MainActor.assumeIsolated {
activity.type
}
activity.type
}

internal override var activityTitle: String? {
MainActor.assumeIsolated {
activity.title
}
activity.title
}

internal override var activityImage: UIImage? {
MainActor.assumeIsolated {
activity.image
}
activity.image
}

internal override var activityViewController: UIViewController? {
Expand All @@ -55,16 +66,12 @@ internal final class SharingActivityManager<Activity: SharingCustomActivity>: UI

internal override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
let activityItems = activityItems.map(SharingItem.init(activityItem:))
return MainActor.assumeIsolated {
activity.isApplicable(for: activityItems)
}
return activity.isApplicable(for: activityItems)
}

internal override func prepare(withActivityItems activityItems: [Any]) {
let activityItems = activityItems.map(SharingItem.init(activityItem:))
MainActor.assumeIsolated {
items = activityItems
}
items = activityItems
}

internal override func perform() {
Expand Down

0 comments on commit 6c39a69

Please sign in to comment.