-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlighting parsed date when typing new reminder - Related to #136
- Loading branch information
1 parent
9f47b9a
commit 4510abf
Showing
7 changed files
with
170 additions
and
104 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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import Foundation | ||
|
||
extension String { | ||
func substringRange(_ range: NSRange) -> String { | ||
func substring(in range: NSRange) -> String { | ||
let start = self.index(self.startIndex, offsetBy: range.lowerBound) | ||
let end = self.index(self.startIndex, offsetBy: range.upperBound) | ||
let subString = self[start..<end] | ||
return String(subString) | ||
} | ||
|
||
var fullRange: NSRange { | ||
return NSRange(location: 0, length: self.count) | ||
} | ||
} |
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
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 @@ | ||
import SwiftUI | ||
|
||
struct FocusOnReceive: ViewModifier { | ||
let publisher: Published<Bool>.Publisher | ||
|
||
init(_ publisher: Published<Bool>.Publisher) { | ||
self.publisher = publisher | ||
} | ||
|
||
@ViewBuilder | ||
func body(content: Content) -> some View { | ||
if #available(macOS 12.0, *) { | ||
content | ||
.modifier(FocusOnReceiveWhenAvailable(publisher: publisher)) | ||
} else { | ||
content | ||
} | ||
} | ||
} | ||
|
||
@available(macOS 12.0, *) | ||
private struct FocusOnReceiveWhenAvailable: ViewModifier { | ||
let publisher: Published<Bool>.Publisher | ||
@FocusState private var textFieldInFocus: Bool | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.focused($textFieldInFocus) | ||
.onReceive(publisher) { _ in | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { | ||
self.textFieldInFocus = true | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.