Skip to content

Commit

Permalink
Fix the initial HorizontalScroll position change
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelHolec committed Aug 9, 2024
1 parent 7da1b42 commit bd2e232
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Sources/Orbit/Support/Layout/HorizontalScrollPosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ struct HorizontalScrollPositionModifier: ViewModifier {
func body(content: Content) -> some View {
HorizontalScrollReader { proxy in
content
.onChange(of: position) {
.onChange(of: position) { newValue in
if isModified {
isModified = false
return
}
proxy.scrollTo($0, animated: animated)
proxy.scrollTo(newValue, animated: animated)
}
.onPreferenceChange(HorizontalScrollScrolledItemIDKey.self) {
isModified = true
position = $0
.onPreferenceChange(HorizontalScrollScrolledItemIDKey.self) { value in
if position != value {
isModified = true
position = value
}
}
}
}
Expand Down

0 comments on commit bd2e232

Please sign in to comment.