Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda