Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
SwiftUI how to prevent scrolling behavior of List if screen is big enough

I have a List with several text field items and sliders.

For smaller screens, I want to make it scrollable because the content can't fit on the screen. (which is the default behavior).

For larger screens, I want to disable the scrolling behavior, because it can fit on the screen. Scrolling will make slider a bit hard to use.

If the List is scrollable, I want to make the keyboard dismiss mode .onDrag. Otherwise I want to make it .interactive.

How I can do that?

My implementation is simply a standard List, which is under a NavigationView

// under Navigation View
List {
  Section {
    TextField(..)
    Slider(..)
  }
  Section {
    // More Stuff
  }
}
.onAppear {
  // Need to be .onDrag if scrollable, and .interactive if not
  UIScrollView.appearance().keyboardDismissMode = .onDrag
}

I don't like VStack UI because List has nice section UI out of box.

I have seen this question SwfitUI List Make Scrolling disabled but it's not helpful.

Minimal reproducible code:

// This should not be scrollable
struct HomeView {
  var body: some View {
    List {
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
    }
  }
}

// This should be scrollable
struct HomeView2 {
  var body: some View {
    List {
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
      Text("foo")
    }
  }
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!