-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
554111e
commit 65bdb5c
Showing
18 changed files
with
1,099 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// flex-ui | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - FlexCompatible | ||
|
||
/// A protocol that adds flexibility to any type by allowing it to be wrapped in a `FlexUI` component. | ||
/// Types conforming to this protocol can use the `flex` property to access a `FlexUI` wrapper for further customization. | ||
public protocol FlexCompatible { | ||
/// The associated type representing the component wrapped by `FlexUI`. | ||
associatedtype ComponentType | ||
|
||
/// A computed property that returns a `FlexUI` wrapper for the current instance. | ||
/// This allows for easy configuration and manipulation of the component. | ||
var flex: FlexUI<ComponentType> { get } | ||
} | ||
|
||
public extension FlexCompatible { | ||
/// Default implementation of the `flex` property for types conforming to `FlexCompatible`. | ||
/// This wraps the current instance in a `FlexUI` component, allowing for configuration. | ||
var flex: FlexUI<Self> { | ||
FlexUI(component: self) | ||
} | ||
} | ||
|
||
// MARK: - NSObject + FlexCompatible | ||
|
||
/// Extension to make `NSObject` conform to `FlexCompatible`. | ||
/// This enables all `NSObject` instances to be wrapped with a `FlexUI` component, | ||
/// providing them with the flexibility to be configured easily. | ||
extension NSObject: FlexCompatible {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// flex-ui | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
/// A generic class that represents a flexible UI component. | ||
/// This class allows you to wrap any component and provide additional flexibility for customization or configuration. | ||
public final class FlexUI<Component> { | ||
/// The wrapped UI component of the specified type. | ||
/// This component is passed during initialization and can be accessed for further customization. | ||
public let component: Component | ||
|
||
/// Initializes a new instance of `FlexUI` with the provided component. | ||
/// | ||
/// - Parameter component: The component to be wrapped by `FlexUI`. | ||
/// This allows you to configure the component later as needed. | ||
public init(component: Component) { | ||
self.component = component | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// flex-ui | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
/// An extension to `FlexUI` that adds helper methods for configuring `UIStackView` properties. | ||
/// These methods enable easy configuration of common `UIStackView` properties using a fluent interface. | ||
extension FlexUI where Component: UIStackView { | ||
/// Sets the axis along which the arranged views in the stack are laid out. | ||
/// | ||
/// - Parameter axis: The axis for layout (either `.horizontal` or `.vertical`). | ||
/// - Returns: The current instance of `FlexUI` for further configuration. | ||
@discardableResult | ||
@MainActor | ||
func axis(_ axis: NSLayoutConstraint.Axis) -> Self { | ||
component.axis = axis | ||
return self | ||
} | ||
|
||
/// Sets the distribution method for the arranged views in the stack. | ||
/// | ||
/// - Parameter distribution: The distribution method (e.g., `.fill`, `.equalSpacing`, etc.). | ||
/// | ||
/// - Returns: The current instance of `FlexUI` for further configuration. | ||
@discardableResult | ||
@MainActor | ||
func distribution(_ distribution: UIStackView.Distribution) -> Self { | ||
component.distribution = distribution | ||
return self | ||
} | ||
|
||
/// Sets the spacing between the arranged views in the stack. | ||
/// | ||
/// - Parameter space: The spacing value (in points) between the arranged views. | ||
/// | ||
/// - Returns: The current instance of `FlexUI` for further configuration. | ||
@discardableResult | ||
@MainActor | ||
func spacing(_ space: CGFloat) -> Self { | ||
component.spacing = space | ||
return self | ||
} | ||
|
||
/// Sets the alignment of the arranged views along the stack's axis. | ||
/// | ||
/// - Parameter alignment: The alignment option (e.g., `.fill`, `.leading`, `.center`, etc.). | ||
/// | ||
/// - Returns: The current instance of `FlexUI` for further configuration. | ||
@discardableResult | ||
@MainActor | ||
func alignment(_ alignment: UIStackView.Alignment) -> Self { | ||
component.alignment = alignment | ||
return self | ||
} | ||
|
||
/// Adds an array of subviews to the stack view's arranged subviews. | ||
/// | ||
/// - Parameter subviews: The array of `UIView` instances to be added to the stack view. | ||
/// | ||
/// - Returns: The current instance of `FlexUI` for further configuration. | ||
@discardableResult | ||
@MainActor | ||
func addArrangeSubviews(_ subviews: [UIView]) -> Self { | ||
subviews.forEach { component.addArrangedSubview($0) } | ||
return self | ||
} | ||
|
||
/// Sets the layout margins for the stack view and enables layout margins relative arrangement. | ||
/// | ||
/// - Parameter value: The directional layout margins (insets) to apply to the stack view. | ||
/// | ||
/// - Returns: The current instance of `FlexUI` for further configuration. | ||
@discardableResult | ||
@MainActor | ||
func layoutMargins(_ value: NSDirectionalEdgeInsets) -> Self { | ||
component.isLayoutMarginsRelativeArrangement = true | ||
component.directionalLayoutMargins = value | ||
return self | ||
} | ||
} |
Oops, something went wrong.