Home > Software engineering >  SwiftUI: How to Disable List Scrolling on Reusable View
SwiftUI: How to Disable List Scrolling on Reusable View

Time:01-28

I've got an interesting glitch in SwiftUI -

I'm using a List as part of my interface that is intended to be un-scrollable. This is how I've designed it:

List {
    ForEach(myArr) {
        ...
    }
}
.listStyle(.plain)
.onAppear { 
    UIScrollView.appearance().isScrollEnabled = false
    UIScrollView.appearance().showsVerticalScrollIndicator = false
}

Now, when I first load the view containing this list, it works perfectly; you cannot scroll this list. However, if I navigate to a different page in my application and then back to the page containing this list (which creates a new instance of the view), scrolling becomes enabled.

How can I fix this?

CodePudding user response:

Use .disabled(true) on the list to disable interaction with the list.

  •  Tags:  
  • Related