Friday, July 12, 2024
HomeiOS Developmentios - SwiftUI allow scrolling of Record inside a disabled ScrollView

ios – SwiftUI allow scrolling of Record inside a disabled ScrollView


I’ve a Record inside a ScrollView that’s scroll disabled. The Record additionally disables and can’t be enabled. I want the ScrollView to not scroll by drag gesture. Is there a technique to enable the Record to scroll however the mother or father ScrollView to have scrolling disabled?

Right here is an instance.

struct TestScroll: View {
    @State var scrollId: String = "first"
    var physique: some View {
        GeometryReader { geoProxy in
            VStack {
                ScrollView(.horizontal) {
                    ScrollViewReader { scrollProxy in
                        HStack {
                            Record(0..<25) { index in
                                Textual content("Merchandise-(index)")
                            }
                            .scrollDisabled(false) // <- That is ignored
                            .body(width: geoProxy.body(in: .international).measurement.width)
                            .id("first")
                            Textual content("Second View")
                                .body(width: geoProxy.body(in: .international).measurement.width)
                                .id("second")
                            Textual content("Third View")
                                .body(width: geoProxy.body(in: .international).measurement.width)
                                .id("third")
                        }
                        .onChange(of: scrollId, carry out: { worth in
                            scrollProxy.scrollTo(worth)
                        })
                    }
                    .tabViewStyle(.web page(indexDisplayMode: .by no means))
                }
                .scrollDisabled(true) // <- Disables all scrolling
                HStack(spacing: 20.0) {
                    Button("First View", motion: {scrollId = "first"})
                    Button("Second View", motion: {scrollId = "second"})
                    Button("Third View", motion: {scrollId = "third"})
                }
            }
        }
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments