Skip to content

chore: address concurrency warning on onPreferenceChange #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/MarkdownUI/Utility/ResizeToFit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ private struct ResizeToFit1<Content>: View where Content: View {
.preference(key: SizePreference.self, value: size)
}
.frame(width: size?.width, height: size?.height)
.onPreferenceChange(SizePreference.self) { size in
self.size = size
.onPreferenceChange(SizePreference.self) { [$size] size in
// Roundabout capture makes closure sendable (see #389)
$size.wrappedValue = size
}
}

Expand Down
5 changes: 3 additions & 2 deletions Sources/MarkdownUI/Views/Blocks/BlockSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ where
VStack(alignment: self.textAlignment.alignment.horizontal, spacing: 0) {
ForEach(self.data, id: \.self) { element in
self.content(element.index, element.value)
.onPreferenceChange(BlockMarginsPreference.self) { value in
self.blockMargins[element.hashValue] = value
.onPreferenceChange(BlockMarginsPreference.self) { [marginBinding = $blockMargins[element.hashValue]] value in
// Roundabout capture makes closure sendable (see #389)
marginBinding.wrappedValue = value
}
.padding(.top, self.topPaddingLength(for: element))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension View {
)
}

func onColumnWidthChange(perform action: @escaping ([Int: CGFloat]) -> Void) -> some View {
func onColumnWidthChange(perform action: @escaping @Sendable ([Int: CGFloat]) -> Void) -> some View {
self.onPreferenceChange(ColumnWidthPreference.self, perform: action)
}
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/MarkdownUI/Views/Blocks/NumberedListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ struct NumberedListView: View {
)
.environment(\.listLevel, self.listLevel + 1)
.environment(\.tightSpacingEnabled, self.isTight)
.onColumnWidthChange { columnWidths in
self.markerWidth = columnWidths[0]
.onColumnWidthChange { [$markerWidth] columnWidths in
// Roundabout capture makes closure sendable (see #389)
$markerWidth.wrappedValue = columnWidths[0]
}
}
}