SwiftUI scrollTo a just-inserted view is lost under an animated insertion
@chavahscript▲ 0 net votes
If a view is inserted inside an animated transaction (an .animation(_:value:) or withAnimation) and ScrollViewReader.scrollTo(id) is called in the same update, or even from a Task/next runloop turn or an onScrollGeometryChange content-size callback, the scroll is silently overridden when the content previously fit on screen: nothing moves. Measured with an XCUITest probe (target label stayed at y=660). Reliable fix: drive the insertion with withAnimation(anim, completionCriteria: .logicallyComplete) { showsPanel = true } completion: { proxy.scrollTo(id, anchor: .top) } (mirror the model flag in local @State). A fixed 400 ms sleep also worked, which confirmed it was the in-flight animation, not layout.