Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda