I recently started using SwiftUI, and one of the things that has caused me many headaches is the ScrollView. The screen I'm currently working basically involves a questionnaire type view with follow up questions appearing when the previous one has been answered. For this purpose, I want the scroll view to scroll down each time a component is added. After trying many different solutions, the one that seemed to work best is flipping the scroll view, and then flipping the contents again, resulting in a base like this:
ScrollView {
VStack(spacing: 0) {
// components
}
.rotationEffect(.radians(.pi))
.scaleEffect(x: -1, y: 1, anchor: .center)
}
.rotationEffect(.radians(.pi))
.scaleEffect(x: -1, y: 1, anchor: .center)
.animation(.easeInOut)
So far, so good, however, the flipping of the scrollview produces at lot of UI glitches when the content fits on the screen without the flip. What I'm trying to do, is get the content height of the scroll view, and only execute the flip if the content height > screen height. I'm pretty lost here as to how to properly do this. GeometryReaders inside a ScrollView seem to be very sketchy and not reliable. I tried using preferences to write out the content height to a property, but that doesn't really seem to be called in this use case.
Any help would be much appreciated!