Task edition improvements (#9)
This PR contains the work done to improve upon the editing experience on the **Task list item and the **New task** views. Reviewed-on: rock-n-code/todos-app#9 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #9.
This commit is contained in:
@@ -21,6 +21,10 @@ struct NewTaskView: View {
|
||||
/// SwiftData model context for saving todo tasks.
|
||||
@Environment(\.modelContext)
|
||||
private var modelContext
|
||||
|
||||
/// Tracks which text field currently has keyboard focus.
|
||||
@FocusState
|
||||
private var inputFocus: InputFieldFocus?
|
||||
|
||||
/// The view model managing the state and logic for this view.
|
||||
@State
|
||||
@@ -50,22 +54,36 @@ struct NewTaskView: View {
|
||||
Section("view.new-task.section.task") {
|
||||
TextField(
|
||||
"view.new-task.placeholder.title",
|
||||
text: $viewModel.title
|
||||
text: $viewModel.title,
|
||||
axis: .vertical
|
||||
)
|
||||
.focused(
|
||||
$inputFocus,
|
||||
equals: .title
|
||||
)
|
||||
.onNewlineFocus(
|
||||
$viewModel.title,
|
||||
to: .note,
|
||||
on: $inputFocus
|
||||
)
|
||||
.autocapitalization(.sentences)
|
||||
.autocorrectionDisabled(false)
|
||||
.keyboardType(.asciiCapable)
|
||||
|
||||
TextField(
|
||||
"view.new-task.placeholder.note",
|
||||
text: $viewModel.note,
|
||||
axis: .vertical
|
||||
)
|
||||
.autocapitalization(.sentences)
|
||||
.autocorrectionDisabled(false)
|
||||
.keyboardType(.asciiCapable)
|
||||
.lineLimit(3 ... 6)
|
||||
.focused(
|
||||
$inputFocus,
|
||||
equals: .note
|
||||
)
|
||||
.onEmptyNewlineResignFocus(
|
||||
text: $viewModel.note,
|
||||
from: $inputFocus
|
||||
)
|
||||
}
|
||||
.autocapitalization(.sentences)
|
||||
.autocorrectionDisabled(false)
|
||||
.keyboardType(.default)
|
||||
|
||||
Section("view.new-task.section.due-date") {
|
||||
DatePicker(
|
||||
@@ -78,6 +96,7 @@ struct NewTaskView: View {
|
||||
}
|
||||
.navigationTitle("view.new-task.navigation.title")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.onResignFocus()
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(role: .cancel) {
|
||||
|
||||
Reference in New Issue
Block a user