Posts

Post marked as solved
2 Replies
Solution: It needs to be inside a ScrollView, List, GeometryReader, or some similar type of view Solution Code: struct MyObject: Identifiable, Equatable { public let id = UUID() public var name: String public var value: String } class MyObjViewModel: ObservableObject { @Published var myObjects: [MyObject] init(_ objects: [MyObject]) { myObjects = objects } } struct ContentView: View { @StateObject var viewModel = MyObjViewModel([ MyObject(name: "aa", value: "1"), MyObject(name: "bb", value: "2"), MyObject(name: "cc", value: "3"), MyObject(name: "dd", value: "4") ]) @State var focus: UUID? var body: some View { VStack { Form { Text("Header") ForEach($viewModel.myObjects) { $obj in FocusField(object: $obj, focus: $focus, nextFocus: { guard let index = viewModel.myObjects.map( { $0.id }).firstIndex(of: obj.id) else { return } focus = viewModel.myObjects.indices.contains(index + 1) ? viewModel.myObjects[index + 1].id : viewModel.myObjects[0].id }) } Text("Footer") } } } } struct FocusField: View { @Binding var object: MyObject @Binding var focus: UUID? var nextFocus: () -> Void @FocusState var isFocused: UUID? var body: some View { TextField("Test", text: $object.value) .onChange(of: focus, perform: { newValue in self.isFocused = newValue }) .focused(self.$isFocused, equals: object.id) .onSubmit { self.nextFocus() } } }
Post marked as solved
3 Replies
Please forgive me lol but this was the fix, I had setNavigationBarHidden(false... instead of true    override func viewDidAppear(_ animated: Bool) {     super.viewDidAppear(true)     navigationController?.setNavigationBarHidden(true, animated: false)   }