Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is SwiftUI picker in form repositioning after navigation?

Tags:

After clicking the picker it navigates to the select view. The item list is rendered too far from the top, but snaps up after the animation is finished. Why is this happening?

Demo: https://gfycat.com/idioticdizzyazurevase

I already created a minimal example to rule out navigation bar titles and buttons, form sections and other details:

import SwiftUI  struct NewProjectView: View {      @State var name = ""      var body: some View {         NavigationView {             Form {                 Picker("Client", selection: $name) {                     Text("Client 1")                     Text("Client 2")                 }             }         }     } }  struct NewProjectView_Previews: PreviewProvider {     static var previews: some View {         NewProjectView()     } } 

This happens in preview mode, simulator and on device (Xcode 11.2, iOS 13.2 in simulator, 13.3 beta 1 on device).

like image 317
Koraktor Avatar asked Nov 08 '19 20:11

Koraktor


1 Answers

The obviously buggy behavior can be worked around when forcing the navigation view style to stacked:

NavigationView {     … }.navigationViewStyle(StackNavigationViewStyle()) 

This is a solution to my problem, but I won‘t mark this as accepted answer (yet).

  1. It seems to be a bug, even if it may be triggered by special circumstances.
  2. My solution won‘t work if you need another navigation view style.
  3. Additionally, it won‘t fix the horizontal repositioning mentioned by DogCoffee in the comments.
like image 79
Koraktor Avatar answered Sep 17 '22 18:09

Koraktor