SwiftUIExt is a collection of extensions and helpers for SwiftUI. These include functions to help streamline the development workflow and/or introduce functionality that isn't included in the native SwiftUI library.
SwiftUIExt is available through CocoaPods. Add the following to your podfile and run pod install
:
pod SwiftUIExt
Simply add https://github.com/frankfka/SwiftUIExt
as a remote package using Swift Package Manager
Conditional Modifier
- Usage:
self.conditionalModifier(someBool, ifTrue: { $0.applySomeViewModifier() }, ifFalse: { $0.applySomeOtherViewModifier() })
- Applies view modifiers depending on the condition given
Fill Width/Height/Both
- Usage:
someView().fillWidth()
or.fillHeight()
or.fillWidthAndHeight()
- Equivalent to calling
self.frame(minWidth: 0, maxWidth: .infinity)
or its height equivalent
View Type Erasure (Credit goes to Majid and his blog)
- Usage:
someView().eraseToAnyView()
- Equivalent to calling
AnyView(someView())
Embed in Navigation View (Credit goes to Majid and his blog)
- Usage:
someView().embedInNavigationView()
- Equivalent to wrapping
someView()
in aNavigationView
Single Line Text
- Usage:
Text().singleLine()
- Enforces a line limit of 1, equivalent to calling
lineLimit(1)
Multi-Line Text
- Usage:
Text().multiline()
- Enforces no line limit, equivalent to calling
lineLimit(nil)
Color Scheme Preview
- Usage:
ColorSchemePreview { someView() }
- Creates two previews, one for light mode and the other for dark mode
- Not available in
0.0.1
Keyboard Aware Padding (Credit goes to Majid and his blog)
- Usage:
someView().keyboardAwarePadding()
- Applies bottom padding equal to the height of the keyboard
- Not available in
0.0.1