Skip to content

Commit c403769

Browse files
abhayrajjais01Siddhesh2377
authored andcommitted
refactor(ios): consolidate MainActor.run blocks to prevent transient UI states
Merge the two separate MainActor.run calls per progressStream iteration into a single call inside a switch statement. This prevents a brief intermediate render frame where stale values flash before the terminal state handler overrides them. Also resets downloadStage in the .completed path for parity with .failed and catch handlers.
1 parent 71a3156 commit c403769

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

examples/ios/RunAnywhereAI/RunAnywhereAI/Features/Models/ModelSelectionRows.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,12 @@ struct FlatModelRow: View {
356356
let progressStream = try await RunAnywhere.downloadModel(model.id)
357357

358358
for await progress in progressStream {
359-
await MainActor.run {
360-
self.downloadProgress = progress.overallProgress
361-
if progress.stage != .completed {
362-
self.downloadStage = progress.stage
363-
}
364-
}
365-
366359
switch progress.state {
367360
case .completed:
368361
await MainActor.run {
369362
self.downloadProgress = 1.0
370363
self.isDownloading = false
364+
self.downloadStage = .downloading
371365
onDownloadCompleted()
372366
}
373367
return
@@ -381,6 +375,10 @@ struct FlatModelRow: View {
381375
return
382376

383377
default:
378+
await MainActor.run {
379+
self.downloadProgress = progress.overallProgress
380+
self.downloadStage = progress.stage
381+
}
384382
continue
385383
}
386384
}

examples/ios/RunAnywhereAI/RunAnywhereAI/Features/Models/SimplifiedModelsView.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,12 @@ private struct SimplifiedModelRow: View {
357357
let progressStream = try await RunAnywhere.downloadModel(model.id)
358358

359359
for await progress in progressStream {
360-
await MainActor.run {
361-
self.downloadProgress = progress.overallProgress
362-
if progress.stage != .completed {
363-
self.downloadStage = progress.stage
364-
}
365-
}
366-
367360
switch progress.state {
368361
case .completed:
369362
await MainActor.run {
370363
self.downloadProgress = 1.0
371364
self.isDownloading = false
365+
self.downloadStage = .downloading
372366
onDownloadCompleted()
373367
}
374368
return
@@ -382,6 +376,10 @@ private struct SimplifiedModelRow: View {
382376
return
383377

384378
default:
379+
await MainActor.run {
380+
self.downloadProgress = progress.overallProgress
381+
self.downloadStage = progress.stage
382+
}
385383
continue
386384
}
387385
}

0 commit comments

Comments
 (0)