This file contains hidden or 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 StateUpdatedPreferenceKey: PreferenceKey { | |
static var defaultValue: Int = Int.min | |
static func reduce(value: inout Int, nextValue: () -> Int) { | |
value = nextValue() | |
} | |
} | |
struct StateUpdated: View { |
This file contains hidden or 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
/// TrackedValue is a property wrapper that allows you to work around the | |
/// lack of didSet when working with SwiftUI. | |
/// Explanation and example usage at: https://stackoverflow.com/a/60145397/467209 | |
@propertyWrapper | |
struct TrackedValue<Tracked, Value>: DynamicProperty { | |
var trackedHolder: State<ValueHolder<Tracked>> | |
var valueHolder: State<ValueHolder<Value>> | |
init(wrappedValue value: Value, tracked: Tracked) { | |
self.trackedHolder = State(initialValue: ValueHolder(tracked)) |
This file contains hidden or 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
func animation(from notification: Notification) -> Animation? { | |
guard | |
let info = notification.userInfo, | |
let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double, | |
let curveValue = info[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int, | |
let uiKitCurve = UIView.AnimationCurve(rawValue: curveValue) | |
else { | |
return nil | |
} |
OlderNewer