I have ScrollView in LazyVGrid. Inside there is forEach cycle create views that appear. User can create new item in this scrollView. When new view is created using ScrollViewReader I observe change of custom Bool property that toggled and scroll view to top using
.onChange(of: boolProperty) { _ in
withAnimation {
reader.scrollTo(viewModel.items.[0].id, anchor: .top)
}
}
and everything works fine, but if i change [0] to .first like this
.onChange(of: boolProperty) { _ in
withAnimation {
reader.scrollTo(viewModel.items.first?.id, anchor: .top)
}
}
behavior isn't the same and view scrolls only a little bit and not to the top