An implementation of a momentary switch: one that has an on/off state, can be turned on repeatedly, turns off after a delay. If triggered multiple times before the off delay is elapses, it re-schedules the reaction (relative to the last time it was triggered). Ideally used for triggering animations on user interaction, and auto-reverting once they’ve stopped interacting for enough time.
NOTE: The switch itself will operate on the background thread, but the on/off callbacks are executed on the @MainActor.
SwiftUIExtensions Library
An open source library with utilities and extensions for SwiftUI.
Developed as re-usable components for various projects at XII’s iOS, macOS, and watchOS applications.
Installation
Swift Package Manager
SwiftUIExtensionslibrary to add to your projectDependencies
License
See the LICENSE file.
Text case shorthands (Source)
Shorthand for applying the
textCaseViewModifier.Shorthand for stretching
Views (Source)Sets the view’s frame to stretch to fill its parent by setting
maxWidth(and/or)maxHeightbased on the requestedAxis..Horizontalas it’s the more common scenario.centerused as the defaultScenePhasechange shorthand (Source)Calls an
actionwhen theScenePhasehas changed. Avoid performing long-running tasks inactionsince it is called from the main thread.URLopen helpersCross platform (iOS + macOS)
iOS only
iOS keyboard helpers (Source)
HiddenViewshorthand (Source)A specialty view that has no visible representation (clear 0x0 pixel view) but can still have functionality attached (e.g.
onChange(of:)).NOTE: If used in a container view that has spacing (e.g.
VStack) this view will still be counted as one and will add unintended spacing.Avoid animations (Source)
Performs the provided block in a transaction with animations disabled.
Useful for cancelling some animations that are hard to control (e.g. navigation view transitions).
NOTE: This is a bit finicky, use at your own risk.
MomentarySwitchUtility (Source)An implementation of a momentary switch: one that has an on/off state, can be turned on repeatedly, turns off after a delay. If triggered multiple times before the off delay is elapses, it re-schedules the reaction (relative to the last time it was triggered). Ideally used for triggering animations on user interaction, and auto-reverting once they’ve stopped interacting for enough time.
NOTE: The switch itself will operate on the background thread, but the on/off callbacks are executed on the
@MainActor.