Skip to content

Commit

Permalink
Avoid excessively writing the same value to the binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
zmian committed Feb 9, 2024
1 parent f01fa7e commit cf6deb1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/Xcore/SwiftUI/Extensions/Size/View+ReadSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ private struct SizePreferenceKey: PreferenceKey {
extension View {
/// Adds a modifier for this view that binds view size to specified binding.
public func readSize(_ size: Binding<CGSize>) -> some View {
readSize {
size.wrappedValue = $0
readSize { newValue in
let currentValue = size.wrappedValue

// Avoid excessively writing the same value to the binding.
if currentValue != newValue {
size.wrappedValue = newValue
}

}
}

Expand Down

0 comments on commit cf6deb1

Please sign in to comment.