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.
SwiftUIExtensions
library to add to your projectSee the LICENSE file.
extension View {
func standardcase() -> some View
func uppercase() -> some View
func lowercase() -> some View
}
Shorthand for applying the textCase
ViewModifier
.
View
s (Source)extension Axis.Set {
static let None: Axis.Set
static let Horizontal: Axis.Set
static let Vertical: Axis.Set
static let All: Axis.Set
}
extension View {
func stretch(
_ axes: Axis.Set = [.horizontal],
alignment: Alignment = .center
) -> some View
}
Sets the view's frame to stretch to fill its parent by setting maxWidth
(and/or) maxHeight
based on the requested Axis
.
.Horizontal
as it's the more common scenario.center
used as the defaultScenePhase
change shorthand (Source)extension View {
func onScenePhaseChanged(
_ action: @escaping (ScenePhase) -> Void
) -> some View
}
Calls an action
when the ScenePhase
has changed. Avoid performing long-running tasks in action
since it is called from the main thread.
URL
open helpersfunc sendUserToApplicationUrl(_ url: URL)
func sendUserToApplicationUrl(_ urlString: String)
func sendUserToApplicationSettings()
func hideKeyboard()
HiddenView
shorthand (Source)struct HiddenView : View {
init()
var body: some View { get }
}
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.
func doWithoutAnimations(_ block: @escaping () -> Void)
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.
MomentarySwitch
Utility (Source)class MomentarySwitch {
init()
func trigger(
offDelaySeconds: Double = 0.0,
switchOn: @escaping () -> Void,
switchOff: @escaping () -> Void
)
}
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
.
link |
Stars: 1 |
Last commit: 1 year ago |
Initial public release
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics