Skip to content

Instantly share code, notes, and snippets.

@disc0infern0
Last active October 30, 2021 13:08
Show Gist options
  • Save disc0infern0/8297b45fefdac6ef53506b51ead8fcfd to your computer and use it in GitHub Desktop.
Save disc0infern0/8297b45fefdac6ef53506b51ead8fcfd to your computer and use it in GitHub Desktop.
List and FocusState - non functioning
struct Task: Identifiable, Codable {
var id = UUID().uuidString
var text: String = ""
static var examples = [ Task(text: "one"), Task(text: "two")]
}
struct Tasks: View {
enum Field : Hashable { case text }
@State private var tasks = Task.examples
@FocusState private var focusedField: Field?
var body: some View {
List() {
ForEach($tasks) { $task in
TaskRow(task: $task)
.focused($focusedField, equals: .text)
}
}
}
}
struct TaskRow: View {
@EnvironmentObject var vm: TaskListVM
@Binding var task: Task
var body: some View {
HStack {
TextField("Task name", text: $task.text )
}
.swipeActions() {
Button(role: .destructive) {} // -todo: write code to delete task
label: { Label("Delete", systemImage: "delete.left.fill" ) }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment