-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements the following: - Tapping [enter] will insert a new task after the currently selected task - Tapping the "New reminder" button will insert a new task after the currently selected task - The newly added tasks will be focused (i.e. the cursor will be placed in the TextField) - If an empty task loses focus, it will be removed This resolves #63 Signed-off-by: Peter Friese <[email protected]>
- Loading branch information
1 parent
49a8d9f
commit fbcc56f
Showing
4 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// View+Focus.swift | ||
// MakeItSo (iOS) | ||
// | ||
// Created by Peter Friese on 30.10.21. | ||
// Copyright © 2021 Google LLC. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import SwiftUI | ||
|
||
/// Used to manage focus in a `List` view | ||
enum Focusable: Hashable { | ||
case row(id: String) | ||
} | ||
|
||
extension View { | ||
/// Mirror changes between an @Published variable (typically in your View Model) and | ||
/// an @FocusedState variable in a view | ||
func sync<T: Equatable>(_ field1: Binding<T>, _ field2: FocusState<T>.Binding ) -> some View { | ||
self | ||
.onChange(of: field1.wrappedValue) { field2.wrappedValue = $0 } | ||
.onChange(of: field2.wrappedValue) { field1.wrappedValue = $0 } | ||
} | ||
} |
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
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