Skip to content

Commit f8785fb

Browse files
authored
Main actor conformance for the navigator delegates (#511)
1 parent 83d7034 commit f8785fb

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Sources/Navigator/Audiobook/AudioNavigator.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public struct MediaPlaybackInfo {
5050
}
5151
}
5252

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

@@ -108,7 +108,7 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
108108
}
109109
}
110110

111-
public let publication: Publication
111+
public nonisolated let publication: Publication
112112
private let initialLocation: Locator?
113113
private let config: Configuration
114114

@@ -326,7 +326,7 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
326326

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

391391
self.lastLoadedTimeRanges = ranges
392-
self.delegate?.navigator(self, loadedTimeRangesDidChange: ranges)
392+
Task { @MainActor in
393+
self.delegate?.navigator(self, loadedTimeRangesDidChange: ranges)
394+
}
393395
}
394396

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

417419
// Seeks to time

Sources/Navigator/SelectableNavigator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct Selection {
3030
public let frame: CGRect?
3131
}
3232

33-
public protocol SelectableNavigatorDelegate: NavigatorDelegate {
33+
@MainActor public protocol SelectableNavigatorDelegate: NavigatorDelegate {
3434
/// Returns whether the default edit menu (`UIMenuController`) should be displayed for the given `selection`.
3535
///
3636
/// To implement a custom selection pop-up, return false and display your own view using `selection.frame`.

Sources/Navigator/VisualNavigator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public struct VisualNavigatorPresentation {
106106
}
107107
}
108108

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

0 commit comments

Comments
 (0)