Last active
October 30, 2021 13:08
-
-
Save disc0infern0/8297b45fefdac6ef53506b51ead8fcfd to your computer and use it in GitHub Desktop.
List and FocusState - non functioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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