Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Created August 7, 2021 22:34
Show Gist options
  • Save StewartLynch/6542a1dd01f75df4358226b9ee7aeafb to your computer and use it in GitHub Desktop.
Save StewartLynch/6542a1dd01f75df4358226b9ee7aeafb to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State private var names = ["Stewart", "Emily"]
@State private var newName = ""
@FocusState private var isFosused:Bool
var body: some View {
NavigationView {
List() {
ForEach($names, id:\.self) { $name in
TextField(name, text: $name)
.focused($isFosused, equals: true)
.textFieldStyle(.roundedBorder)
}
}
.navigationTitle("Name list")
.navigationBarItems(
trailing:
Button {
names.append("")
} label: {
Image(systemName: "plus.circle.fill")
}
)
}
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
HStack {
Spacer()
Button {
isFosused = false
} label: {
Image(systemName: "keyboard.chevron.compact.down")
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment