0

I fail to make the scroll view able to reach the bottom of its view.

The canvas is made of drawings where the user can touch through captured coordinates. Touching the bottom of the view is impossible due to the fact that the scroll view immediately scrolls up to the initial height of 657.

I've tried to capture the vStackGeometryReader.size.height with a PreferenceKey struct, but it failed to set the height of the main view.

var body: some View {
    VStack {
        Text("…")
        GeometryReader { mainGeometryReader in
            ScrollView(.horizontal, showsIndicators: true) {
                ScrollViewReader { horizontalScrollViewReader in
                    GeometryReader { vStackGeometryReader in
                        VStack {
                            Canvas { headerCanvasContext, headerCanvasSize in

                            }
                            .frame(width: vStackGeometryReader.size.width, height: CanvasConstant.value)
                            ScrollView {
                                Canvas { bodyCanvasContext, bodyCanvasSize in

                                }
                                .frame(width:height) // based on vStackGeometryReader.size
                        }
                    }
                    .frame(width:height) // based on mainGeometryReader.size
                }
            }
        }
    }
}

phbardon
  • 127
  • 9
  • Does this answer your question? [Why won't a nested scrollview respond to scrolls in swiftUI?](https://stackoverflow.com/questions/68668517/why-wont-a-nested-scrollview-respond-to-scrolls-in-swiftui) – Yrb May 26 '23 at 22:02
  • Thank you. No, it doesn't change the behaviour. In my case, the outer ScrollView is moving horizontally and operates appropriately. The inner ScrollView is moving vertically as expected but doesn't stay in place when moving out of the screen boundary. – phbardon May 27 '23 at 01:24
  • Understood. Your best bet is a different UI. Nested ScrollViews are problematic at best. – Yrb May 28 '23 at 13:06
  • Indeed. Finally, calculating the vStackGeometryReader's height a different way helped to solve partially the issue, but it's more a patch than a definitive and satisfactory solution. Thank you. – phbardon May 29 '23 at 06:28

0 Answers0