Post

Replies

Boosts

Views

Activity

on Xcode Version 15.0 (15A240d): focusState not work in navigationStack?
its not work on Xcode Version 15.0 (15A240d): focusState is always nil when use focusState in navigationStack. It not work in onAppear && setNextFocus on real device. here is the code: enum NameField { case focus1 case focus2 case focus3 } struct ContentView: View { @State private var text1 = "" @State private var text2 = "" @State private var text3 = "" @FocusState private var nameField: NameField? var body: some View { NavigationStack { VStack { TextField("Field One", text: $text1) .focused($nameField, equals: .focus1) TextField("Field Two", text: $text2) .focused($nameField, equals: .focus2) TextField("Field Three", text: $text3) .focused($nameField, equals: .focus3) } .textFieldStyle(.roundedBorder) .padding(.horizontal) .onAppear { self.nameField = .focus1 } .toolbar { ToolbarItemGroup(placement: .keyboard){ Spacer() Button{ setNextFocus() } label: { HStack { Text("Next") Image(systemName: "rectangle.trailinghalf.inset.filled.arrow.trailing") } .foregroundColor(.orange) } } } } } func setNextFocus() { if nameField == .focus1 { nameField = .focus2 } else if nameField == .focus2 { nameField = .focus3 } else if nameField == .focus3 { nameField = .focus1 } else { // choose what you want to do } } }
0
0
299
Sep ’23