mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-24 18:59:36 +00:00
Cancel stale screenshot loads in the bug report screen
Load the picked screenshot with .task(id:) instead of an unstructured Task so that picking a new item or removing the screenshot cancels any load in progress. Previously a slow load could finish after removal and re-attach the screenshot, or overwrite a newer pick. Clear the picker selection once each load finishes, successful or not, so picking the same item again always triggers a new load.
This commit is contained in:
@@ -37,13 +37,13 @@ struct BugReportScreen: View {
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.interactiveDismissDisabled()
|
||||
.onChange(of: selectedScreenshot) { _, newItem in
|
||||
Task {
|
||||
guard let data = try? await newItem?.loadTransferable(type: Data.self),
|
||||
let image = UIImage(data: data)
|
||||
else {
|
||||
return
|
||||
}
|
||||
.task(id: selectedScreenshot) {
|
||||
guard let selectedScreenshot else { return }
|
||||
let data = try? await selectedScreenshot.loadTransferable(type: Data.self)
|
||||
guard !Task.isCancelled else { return }
|
||||
// Clear the selection so that picking the same item again triggers a new load.
|
||||
self.selectedScreenshot = nil
|
||||
if let data, let image = UIImage(data: data) {
|
||||
context.send(viewAction: .attachScreenshot(image))
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ struct BugReportScreen: View {
|
||||
}
|
||||
|
||||
private func removeScreenshot() {
|
||||
// Otherwise the picker keeps the item checked and re-picking it doesn't trigger onChange.
|
||||
// Cancels any in-flight load so it can't re-attach the screenshot.
|
||||
selectedScreenshot = nil
|
||||
context.send(viewAction: .removeScreenshot)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user