OnAppear calls unexpectedly when Keyboard Appears in SwiftUI

前端 未结 2 921
南笙
南笙 2021-02-02 12:38

I am experiencing very odd behavior in SwiftUI 2.0 and iOS14.

When the keyboard appears on the screen, the OnAppear method of other tab\'s view called automatically.

2条回答
  •  一整个雨季
    2021-02-02 13:07

    Having the same issue myself, I think this is a bug or something like that, however I came up with a solution maybe a workaround until apple will fix it.

    The thing that I did is basically I used a LazyVStack, and this seems to be working perfectly.

    LazyVStack {
        VStack{
            Text(screenName)
                .font(.title)
            
            TextField("Buggy Keyboard Issue", text: $text)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                
            Text("Issue : When keyboard appears, onAppear of other 2 tabs call automatically.")
                .font(.footnote)
        }
        .padding()
        .onAppear(perform: {
            debugPrint("OnAppear of : \(screenName)")
    })
    }
    

    Now the OnAppear method of other tab's view it is not called automatically when the keyboard appear.

提交回复
热议问题