Skip to content

Commit a9763fb

Browse files
authoredMay 5, 2022
Merge pull request #6 from ULazdins/main
Invalidate snapLocations when children configuration changes
2 parents de0a704 + 7a34313 commit a9763fb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎Sources/Views/HStackSnapCore.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public struct HStackSnapCore<Content: View>: View {
3636
// TODO: Make this less... janky.
3737
.frame(width: 10000)
3838
.onPreferenceChange(ContentPreferenceKey.self, perform: { preferences in
39-
39+
self.preferences = preferences
40+
4041
// Calculate all values once, on render. On-the-fly calculations with GeometryReader
4142
// proved occasionally unstable in testing.
4243
if !hasCalculatedFrames {
@@ -133,6 +134,15 @@ public struct HStackSnapCore<Content: View>: View {
133134
}
134135

135136
// MARK: Private
137+
138+
/// Used to check if children configuration (ids or sizes) have changed.
139+
@State private var preferences: [ContentPreferenceData] = [] {
140+
didSet {
141+
if oldValue.map(\.id) != preferences.map(\.id) || oldValue.map { $0.rect.size } != preferences.map { $0.rect.size } {
142+
hasCalculatedFrames = false
143+
}
144+
}
145+
}
136146

137147
@State private var hasCalculatedFrames: Bool = false
138148

0 commit comments

Comments
 (0)