1

I have a screen layout where I have 2 text fields with content that pushes then last Textfield out of the screen: Textfield .... TextField

When I enter data, in the top Textfield, and the click on the bottom textfield, the screen jumps back to the top TextField. Even though the focus is now on the bottom textfield. Think this would be 'standard' behaviour or a 'bug'.

As code is straight forward:

import SwiftUI
import CoreData

struct ContentView: View {
    
    @Environment(\.managedObjectContext) private var viewContext
    
    @State var test = ""
    @State var test1 = ""
    @State var test2 = ""
    @State var test3 = ""
    @State var test4 = ""
    @State var test5 = ""
    @State var test6 = ""
    @State var test7 = ""
    @State var test8 = ""
    @State var test9 = ""
    @State var test10 = ""
    @State var test11 = ""
    @State var test12 = ""
    @State var test13 = ""
    @State var test14 = ""
    @State var test15 = ""
    @State var test16 = ""
    @State var test17 = ""
    @State var test18 = ""
    @State var test19 = ""
    
    var body: some View {
        NavigationView {
            ScrollView {
                VStack{
                    TextField("Test", text: $test, onEditingChanged: {
                        edit in
                        print("Hello")
                    })
        
                    Text("Hello")
                        .font(.system(size: 90))
                    Text("Hello")
                        .font(.system(size: 90))
                    Text("Hello")
                        .font(.system(size: 90))
                    Text("Hello")
                        .font(.system(size: 90))
                    Text("Hello")
                        .font(.system(size: 90))
                    Text("Hello")
                    
                    TextField("Test9", text: $test11, onEditingChanged: {
                        edit in
                        print("Hello")
                    })
                }
            }
         
        }
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
    }
}

Is this standard behaviour?

I would like the focus to change to the field selected not the field data has been entered.

4

0 回答 0