Skip to content

frankfka/SwiftUIExt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUIExt - Extensions for SwiftUI

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.

1 Installation

Cocoapods

SwiftUIExt is available through CocoaPods. Add the following to your podfile and run pod install:

pod SwiftUIExt

Swift Package Manager

Simply add https://github.com/frankfka/SwiftUIExt as a remote package using Swift Package Manager

2 Features (On Master)

2.1 View Extensions

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 a NavigationView

2.2 Text Extensions

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)

2.3 Preview Extensions

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

3.4 Other Helpers

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

About

Useful extensions for SwiftUI

Resources

License

Stars

Watchers

Forks

Packages

No packages published