Turbocharger
Turbocharger aims accelerate SwiftUI development by providing commonly desired views and view modifiers. Highlights include an AdaptiveStack to better support dynamic type and WeightedVStack/WeightedHStack for relational layouts.
Built for performance and backwards compatibility using Engine
See Also
Requirements
- Deployment target: iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0 or visionOS 1.0
- Xcode 16.4+
Installation
Xcode Projects
Select File -> Swift Packages -> Add Package Dependency and enter https://github.com/nathantannar4/Turbocharger.
Swift Package Manager Projects
You can add Turbocharger as a package dependency in your Package.swift file:
let package = Package(
//...
dependencies: [
.package(url: "https://github.com/nathantannar4/Turbocharger"),
],
targets: [
.target(
name: "YourPackageTarget",
dependencies: [
.product(name: "Turbocharger", package: "Turbocharger"),
],
//...
),
//...
],
//...
)
Documentation
Detailed documentation is available here.
Introduction to Turbocharger
Turbocharger was started with the two goals. 1) To expand the standard API that SwiftUI provides to what many would commonly desired or need; and 2) To demonstrate how to use Engine to make reusable components that are backwards compatible.
LabeledView
/// The `ViewStyle for LabeledView
public protocol LabeledViewStyle: ViewStyle where Configuration == LabeledViewStyleConfiguration {
associatedtype Configuration = Configuration
}
/// The
ViewStyledView.Configuration for LabeledView
public struct LabeledViewStyleConfiguration {
/// A type-erased label of a LabeledView
public struct Label: ViewAlias { }
public var label: Label
/// A type-erased content of a
LabeledView
public struct Content: ViewAlias { }
public var content: Content
}
/// A backwards compatible port of
LabeledContent
public struct LabeledView<Label: View, Content: View>: View {
public init(
@ViewBuilder content: () -> Content,
@ViewBuilder label: () -> Label
)
}
HVStack/AdaptiveStack
/// A view that arranges its subviews in a vertical or horizontal line.
@frozen
public struct HVStack<Content: View>: View {
public init(
axis: Axis,
alignment: Alignment = .center,
spacing: CGFloat? = nil,
@ViewBuilder content: () -> Content
)
}
/// A view that arranges its subviews in a horizontal line when such a layout
/// would fit the available space. If there is not enough space, it arranges it's subviews
/// in a vertical line.
@frozen
public struct AdaptiveStack<Content: View>: View {
public init(
alignment: Alignment = .center,
spacing: CGFloat? = nil,
@ViewBuilder content: () -> Content
)
}
WeightedHStack/WeightedVStack
/// A view that arranges its subviews in a horizontal line a width /// that is relative to itsLayoutWeightPriority. /// /// By default, all subviews will be arranged with equal width. /// @frozen public struct WeightedHStack<Content: View>: View {LayoutWeightPrioritypublic init( alignment: VerticalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content ) }
/// A view that arranges its subviews in a vertical line a height /// that is relative to its
. /// /// By default, all subviews will be arranged with equal height. /// @frozen public struct WeightedVStack<Content: View>: View {public init( alignment: HorizontalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content ) }
extension View { @ViewBuilder public func layoutWeight(_ value: Double) -> some View }
FlowStack
/// A view that arranges its subviews along multiple horizontal lines.
@frozen
public struct FlowStack<Content: View>: View {
public init(
alignment: Alignment = .center,
spacing: CGFloat? = nil,
@ViewBuilder content: () -> Content
)
}
RadialStack
/// A view that arranges its subviews along a radial circumference.
@frozen
public struct RadialStack<Content: View>: View {
public init(radius: CGFloat? = nil, @ViewBuilder content: () -> Content)
}
ResultAdapter
/// A view maps aResultvalue to it'sSuccessContentorFailureContent. @frozen public struct ResultAdapter< SuccessContent: View, FailureContent: View >: View {@inlinable public init<Success, Failure: Error>( _ value: Result<Success, Failure>, @ViewBuilder content: (Success) -> SuccessContent, @ViewBuilder placeholder: (Failure) -> FailureContent ) @inlinable public init<Success, Failure: Error>( _ value: Binding<Result<Success, Failure>>, @ViewBuilder content: (Binding<Success>) -> SuccessContent, @ViewBuilder placeholder: (Binding<Failure>) -> FailureContent ) }
extension ResultAdapter where FailureContent == EmptyView { @inlinable public init<Success, Failure: Error>( _ value: Result<Success, Failure>, @ViewBuilder content: (Success) -> SuccessContent ) @inlinable public init<Success, Failure: Error>( _ value: Binding<Result<Success, Failure>>, @ViewBuilder content: (Binding<Success>) -> SuccessContent ) }
Badge
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
extension View {
@inlinable
public func badge<Label: View>(
alignment: Alignment = .topTrailing,
anchor: UnitPoint = UnitPoint(x: 0.25, y: 0.25),
scale: CGFloat = 1.2,
@ViewBuilder label: () -> Label
) -> some View
}
And Many More
See the source files for more.
License
Distributed under the BSD 2-Clause License. See LICENSE.md` for more information.