Skip to content

Commit

Permalink
Main actor conformance for the navigator delegates (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Nov 25, 2024
1 parent 83d7034 commit f8785fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions Sources/Navigator/Audiobook/AudioNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct MediaPlaybackInfo {
}
}

public protocol AudioNavigatorDelegate: NavigatorDelegate {
@MainActor public protocol AudioNavigatorDelegate: NavigatorDelegate {
/// Called when the playback updates.
func navigator(_ navigator: AudioNavigator, playbackDidChange info: MediaPlaybackInfo)

Expand Down Expand Up @@ -108,7 +108,7 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
}
}

public let publication: Publication
public nonisolated let publication: Publication
private let initialLocation: Locator?
private let config: Configuration

Expand Down Expand Up @@ -326,7 +326,7 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo

/// A deadlock can occur when loading HTTP assets and creating the playback info from the main thread.
/// To fix this, this is an asynchronous operation.
private func makePlaybackInfo(forTime time: Double? = nil, completion: @escaping (MediaPlaybackInfo) -> Void) {
private func makePlaybackInfo(forTime time: Double? = nil, completion: @escaping @MainActor (MediaPlaybackInfo) -> Void) {
DispatchQueue.global(qos: .userInteractive).async {
let info = MediaPlaybackInfo(
resourceIndex: self.resourceIndex,
Expand Down Expand Up @@ -389,7 +389,9 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
}

self.lastLoadedTimeRanges = ranges
self.delegate?.navigator(self, loadedTimeRangesDidChange: ranges)
Task { @MainActor in
self.delegate?.navigator(self, loadedTimeRangesDidChange: ranges)
}
}

// MARK: - Navigator
Expand All @@ -411,7 +413,7 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
player.replaceCurrentItem(with: AVPlayerItem(asset: asset))
resourceIndex = newResourceIndex
loadedTimeRangesTimer.fire()
delegate?.navigator(self, loadedTimeRangesDidChange: [])
await delegate?.navigator(self, loadedTimeRangesDidChange: [])
}

// Seeks to time
Expand Down
2 changes: 1 addition & 1 deletion Sources/Navigator/SelectableNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct Selection {
public let frame: CGRect?
}

public protocol SelectableNavigatorDelegate: NavigatorDelegate {
@MainActor public protocol SelectableNavigatorDelegate: NavigatorDelegate {
/// Returns whether the default edit menu (`UIMenuController`) should be displayed for the given `selection`.
///
/// To implement a custom selection pop-up, return false and display your own view using `selection.frame`.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Navigator/VisualNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public struct VisualNavigatorPresentation {
}
}

public protocol VisualNavigatorDelegate: NavigatorDelegate {
@MainActor public protocol VisualNavigatorDelegate: NavigatorDelegate {
/// Called when the navigator presentation changed, for example after
/// applying a new set of preferences.
func navigator(_ navigator: Navigator, presentationDidChange presentation: VisualNavigatorPresentation)
Expand Down

0 comments on commit f8785fb

Please sign in to comment.