Skip to content

Commit ac67c05

Browse files
committed
Replace custom MainActor.ensureIsolated with Task { @mainactor, but where sync is required, use a LLC style DispatchQueue addition
1 parent fe9dc14 commit ac67c05

File tree

43 files changed

+169
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+169
-165
lines changed

Sources/StreamChatUI/Appearance.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public struct Appearance: @unchecked Sendable {
4141
public extension Appearance {
4242
static var `default`: Appearance {
4343
get {
44-
MainActor.ensureIsolated { _default }
44+
DispatchQueue.performSynchronouslyOnMainQueue { _default }
4545
}
4646
set {
47-
MainActor.ensureIsolated { _default = newValue }
47+
DispatchQueue.performSynchronouslyOnMainQueue { _default = newValue }
4848
}
4949
}
5050

Sources/StreamChatUI/ChatChannel/ChatChannelHeaderView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ open class ChatChannelHeaderView: _View,
104104
withTimeInterval: statusUpdateInterval,
105105
repeats: true
106106
) { [weak self] _ in
107-
MainActor.ensureIsolated { [weak self] in
107+
Task { @MainActor [weak self] in
108108
self?.updateContentIfNeeded()
109109
}
110110
}
@@ -116,7 +116,7 @@ open class ChatChannelHeaderView: _View,
116116
_ channelController: ChatChannelController,
117117
didUpdateChannel channel: EntityChange<ChatChannel>
118118
) {
119-
MainActor.ensureIsolated {
119+
Task { @MainActor in
120120
switch channel {
121121
case .update, .create:
122122
updateContent()
@@ -151,7 +151,7 @@ open class ChatChannelHeaderView: _View,
151151
}
152152

153153
deinit {
154-
MainActor.ensureIsolated {
154+
DispatchQueue.performSynchronouslyOnMainQueue {
155155
timer?.invalidate()
156156
}
157157
}

Sources/StreamChatUI/ChatChannel/ChatChannelVC.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ open class ChatChannelVC: _ViewController,
149149

150150
channelController.delegate = self
151151
channelController.synchronize { [weak self] error in
152-
MainActor.ensureIsolated { [weak self] in
152+
Task { @MainActor [weak self] in
153153
self?.didFinishSynchronizing(with: error)
154154
}
155155
}
@@ -314,7 +314,7 @@ open class ChatChannelVC: _ViewController,
314314
open func loadPreviousMessages(completion: @escaping @Sendable(Error?) -> Void) {
315315
channelController.loadPreviousMessages { [weak self] error in
316316
completion(error)
317-
MainActor.ensureIsolated { [weak self] in
317+
Task { @MainActor [weak self] in
318318
self?.didFinishLoadingPreviousMessages(with: error)
319319
}
320320
}
@@ -329,7 +329,7 @@ open class ChatChannelVC: _ViewController,
329329
/// Called when the channel will load next (newer) messages.
330330
open func loadNextMessages(completion: @escaping @Sendable(Error?) -> Void) {
331331
channelController.loadNextMessages { [weak self] error in
332-
MainActor.ensureIsolated { [weak self] in
332+
Task { @MainActor [weak self] in
333333
completion(error)
334334
self?.didFinishLoadingNextMessages(with: error)
335335
}
@@ -392,7 +392,7 @@ open class ChatChannelVC: _ViewController,
392392
}
393393

394394
channelController.loadPageAroundMessageId(messageId) { [weak self] error in
395-
MainActor.ensureIsolated { [weak self] in
395+
Task { @MainActor [weak self] in
396396
self?.updateJumpToUnreadRelatedComponents()
397397
completion(error)
398398
}
@@ -441,7 +441,7 @@ open class ChatChannelVC: _ViewController,
441441
case is MarkUnreadActionItem:
442442
dismiss(animated: true) { [weak self] in
443443
self?.channelController.markUnread(from: message.id) { result in
444-
MainActor.ensureIsolated {
444+
Task { @MainActor in
445445
if case let .success(channel) = result {
446446
self?.updateAllUnreadMessagesRelatedComponents(channel: channel)
447447
}
@@ -520,7 +520,7 @@ open class ChatChannelVC: _ViewController,
520520
_ channelController: ChatChannelController,
521521
didUpdateMessages changes: [ListChange<ChatMessage>]
522522
) {
523-
MainActor.ensureIsolated {
523+
Task { @MainActor in
524524
_channelController(channelController, didUpdateMessages: changes)
525525
}
526526
}
@@ -554,7 +554,7 @@ open class ChatChannelVC: _ViewController,
554554
_ channelController: ChatChannelController,
555555
didUpdateChannel channel: EntityChange<ChatChannel>
556556
) {
557-
MainActor.ensureIsolated {
557+
Task { @MainActor in
558558
_channelController(channelController, didUpdateChannel: channel)
559559
}
560560
}
@@ -577,7 +577,7 @@ open class ChatChannelVC: _ViewController,
577577
_ channelController: ChatChannelController,
578578
didChangeTypingUsers typingUsers: Set<ChatUser>
579579
) {
580-
MainActor.ensureIsolated {
580+
Task { @MainActor in
581581
_channelController(channelController, didChangeTypingUsers: typingUsers)
582582
}
583583
}
@@ -602,7 +602,7 @@ open class ChatChannelVC: _ViewController,
602602
// MARK: - EventsControllerDelegate
603603

604604
nonisolated open func eventsController(_ controller: EventsController, didReceiveEvent event: Event) {
605-
MainActor.ensureIsolated {
605+
Task { @MainActor in
606606
_eventsController(controller, didReceiveEvent: event)
607607
}
608608
}
@@ -643,7 +643,7 @@ open class ChatChannelVC: _ViewController,
643643
_ audioPlayer: AudioPlaying,
644644
currentAssetURL: URL?
645645
) -> URL? {
646-
MainActor.ensureIsolated {
646+
DispatchQueue.performSynchronouslyOnMainQueue {
647647
audioQueuePlayerNextItemProvider.findNextItem(
648648
in: messages,
649649
currentVoiceRecordingURL: currentAssetURL,

Sources/StreamChatUI/ChatChannelList/ChatChannelListVC.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ open class ChatChannelListVC: _ViewController,
276276
isPaginatingChannels = true
277277

278278
controller.loadNextChannels { [weak self] _ in
279-
MainActor.ensureIsolated { [weak self] in
279+
Task { @MainActor [weak self] in
280280
self?.isPaginatingChannels = false
281281
}
282282
}
@@ -406,7 +406,7 @@ open class ChatChannelListVC: _ViewController,
406406
// MARK: - ChatChannelListControllerDelegate
407407

408408
nonisolated open func controllerWillChangeChannels(_ controller: ChatChannelListController) {
409-
MainActor.ensureIsolated {
409+
Task { @MainActor in
410410
collectionView.layoutIfNeeded()
411411
}
412412
}
@@ -415,7 +415,7 @@ open class ChatChannelListVC: _ViewController,
415415
_ controller: ChatChannelListController,
416416
didChangeChannels changes: [ListChange<ChatChannel>]
417417
) {
418-
MainActor.ensureIsolated {
418+
Task { @MainActor in
419419
handleStateChanges(controller.state)
420420

421421
if skipChannelUpdates {
@@ -430,7 +430,7 @@ open class ChatChannelListVC: _ViewController,
430430
// MARK: - DataControllerStateDelegate
431431

432432
nonisolated open func controller(_ controller: DataController, didChangeState state: DataController.State) {
433-
MainActor.ensureIsolated {
433+
Task { @MainActor in
434434
handleStateChanges(state)
435435
}
436436
}

Sources/StreamChatUI/ChatChannelList/Search/ChatChannelListSearchVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ open class ChatChannelListSearchVC: ChatChannelListVC, UISearchResultsUpdating {
120120
// MARK: - Deinit
121121

122122
deinit {
123-
MainActor.ensureIsolated {
123+
DispatchQueue.performSynchronouslyOnMainQueue {
124124
debouncer.invalidate()
125125
}
126126
}

Sources/StreamChatUI/ChatChannelList/Search/ChatMessageSearchVC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ open class ChatMessageSearchVC: ChatChannelListSearchVC, ChatMessageSearchContro
6161
isPaginatingMessages = true
6262

6363
messageSearchController.loadNextMessages { [weak self] _ in
64-
MainActor.ensureIsolated { [weak self] in
64+
Task { @MainActor [weak self] in
6565
self?.isPaginatingMessages = false
6666
}
6767
}
@@ -108,7 +108,7 @@ open class ChatMessageSearchVC: ChatChannelListSearchVC, ChatMessageSearchContro
108108
// MARK: - ChatMessageSearchControllerDelegate
109109

110110
nonisolated open func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange<ChatMessage>]) {
111-
MainActor.ensureIsolated {
111+
Task { @MainActor in
112112
reloadMessages()
113113
}
114114
}

Sources/StreamChatUI/ChatMessageList/Attachments/ChatMessageAttachmentPreviewVC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ open class ChatMessageAttachmentPreviewVC: _ViewController, WKNavigationDelegate
103103
// MARK: - WKNavigationDelegate
104104

105105
nonisolated public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
106-
MainActor.ensureIsolated {
106+
Task { @MainActor in
107107
activityIndicatorView.startAnimating()
108108
}
109109
}
110110

111111
nonisolated public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
112-
MainActor.ensureIsolated {
112+
Task { @MainActor in
113113
activityIndicatorView.stopAnimating()
114114

115115
webView.evaluateJavaScript("document.title") { data, _ in

Sources/StreamChatUI/ChatMessageList/Attachments/Gallery/ChatMessageImageGallery+ImagePreview.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extension ChatMessageGalleryView {
9595
from: attachment?.payload,
9696
maxResolutionInPixels: components.imageAttachmentMaxPixels
9797
) { [weak self] _ in
98-
MainActor.ensureIsolated { [weak self] in
98+
Task { @MainActor [weak self] in
9999
self?.loadingIndicator.isVisible = false
100100
self?.imageTask = nil
101101
}
@@ -115,7 +115,7 @@ extension ChatMessageGalleryView {
115115
// MARK: - Init & Deinit
116116

117117
deinit {
118-
MainActor.ensureIsolated {
118+
DispatchQueue.performSynchronouslyOnMainQueue {
119119
imageTask?.cancel()
120120
}
121121
}

Sources/StreamChatUI/ChatMessageList/Attachments/Gallery/VideoAttachmentGalleryPreview.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ open class VideoAttachmentGalleryPreview: _View, ThemeProvider {
8989
showPreview(using: thumbnailURL)
9090
} else if let url = content?.videoURL {
9191
components.videoLoader.loadPreviewForVideo(at: url) { [weak self] result in
92-
MainActor.ensureIsolated { [weak self] in
92+
Task { @MainActor [weak self] in
9393
self?.loadingIndicator.isHidden = true
9494
switch result {
9595
case let .success(preview):
@@ -107,7 +107,7 @@ open class VideoAttachmentGalleryPreview: _View, ThemeProvider {
107107

108108
private func showPreview(using thumbnailURL: URL) {
109109
components.imageLoader.downloadImage(with: .init(url: thumbnailURL, options: ImageDownloadOptions())) { [weak self] result in
110-
MainActor.ensureIsolated { [weak self] in
110+
Task { @MainActor [weak self] in
111111
self?.loadingIndicator.isHidden = true
112112
guard case let .success(image) = result else { return }
113113
self?.showPreview(using: image)

Sources/StreamChatUI/ChatMessageList/Attachments/Poll/PollAllOptionsListVC/PollAllOptionsListVC.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ open class PollAllOptionsListVC:
162162
if let currentUserVote = pollController.poll?.currentUserVote(for: option) {
163163
pollController.removePollVote(voteId: currentUserVote.id) { [weak self] error in
164164
if error != nil {
165-
MainActor.ensureIsolated { [weak self] in
165+
Task { @MainActor [weak self] in
166166
self?.notificationFeedbackGenerator?.notificationOccurred(.error)
167167
}
168168
}
169169
}
170170
} else {
171171
pollController.castPollVote(answerText: nil, optionId: option.id) { [weak self] error in
172172
if error != nil {
173-
MainActor.ensureIsolated { [weak self] in
173+
Task { @MainActor [weak self] in
174174
self?.notificationFeedbackGenerator?.notificationOccurred(.error)
175175
}
176176
}
@@ -181,7 +181,7 @@ open class PollAllOptionsListVC:
181181
// MARK: - PollControllerDelegate
182182

183183
nonisolated open func pollController(_ pollController: PollController, didUpdatePoll poll: EntityChange<Poll>) {
184-
MainActor.ensureIsolated {
184+
Task { @MainActor in
185185
tableView.reloadData()
186186
}
187187
}

0 commit comments

Comments
 (0)