Skip to content

Commit

Permalink
Implement the flex-ui package
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-vasilev committed Dec 30, 2024
1 parent 554111e commit 65bdb5c
Show file tree
Hide file tree
Showing 18 changed files with 1,099 additions and 68 deletions.
42 changes: 1 addition & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,12 @@ jobs:
with:
args: --strict
env:

DIFF_BASE: ${{ github.base_ref }}





iOS:

name: ${{ matrix.name }}
runs-on: ${{ matrix.runsOn }}

env:

DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer"

timeout-minutes: 20
strategy:
fail-fast: false
Expand All @@ -54,31 +44,17 @@ jobs:
runsOn: macos-13
steps:
- uses: actions/checkout@v3

- name: ${{ matrix.name }}
run: xcodebuild test -scheme "{{ cookiecutter.name }}" -destination "${{ matrix.destination }}" clean -enableCodeCoverage YES -resultBundlePath "test_output/${{ matrix.name }}.xcresult" || exit 1

- uses: actions/upload-artifact@v4
with:

name: ${{ matrix.name }}
path: test_output







spm:

name: ${{ matrix.name }}
runs-on: ${{ matrix.runsOn }}

env:

DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer"

timeout-minutes: 20
strategy:
fail-fast: false
Expand All @@ -92,28 +68,12 @@ jobs:
runsOn: macos-13
steps:
- uses: actions/checkout@v3

- name: ${{ matrix.name }}
run: swift build -c release --target "{{ cookiecutter.name }}"

merge-test-reports:
needs: [iOS, macOS, watchOS, tvOS]
runs-on: macos-13
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: test_output
- run: xcrun xcresulttool merge test_output/**/*.xcresult --output-path test_output/final/final.xcresult
- name: Upload Merged Artifact
uses: actions/upload-artifact@v4
with:
name: MergedResult
path: test_output/final

discover-typos:
name: Discover Typos
runs-on: macOS-12
runs-on: macOS-14
env:
DEVELOPER_DIR: /Applications/Xcode_14.1.app/Contents/Developer
steps:
Expand Down
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bootstrap: hook
mint bootstrap

hook:
ln -sf .git/hooks/pre-commit ../../hooks/pre-commit
ln -sf ../../hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

mint:
Expand Down
17 changes: 5 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ import PackageDescription

let package = Package(
name: "flex-ui",
defaultLocalization: "en",
platforms: [.iOS(.v14)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "flex-ui",
targets: ["flex-ui"]),
.library(name: "FlexUI", targets: ["FlexUI"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "flex-ui"),
.testTarget(
name: "flex-uiTests",
dependencies: ["flex-ui"]
),
.target(name: "FlexUI"),
.testTarget(name: "FlexUITests", dependencies: ["FlexUI"]),
]
)
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
<a href="https://swiftpackageindex.com/space-code/flex-ui"><img alt="Swift Compatibility" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fspace-code%2Fflex-ui%2Fbadge%3Ftype%3Dswift-versions"/></a>
<a href="https://swiftpackageindex.com/space-code/flex-ui"><img alt="Platform Compatibility" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fspace-code%2Fflex-ui%2Fbadge%3Ftype%3Dplatforms"/></a>
<a href="https://github.com/space-code/flex-ui"><img alt="CI" src="https://github.com/space-code/flex-ui/actions/workflows/ci.yml/badge.svg?branch=main"></a>

<a href="https://github.com/space-code/flex-ui"><img alt="Number of GitHub contributors" src="https://img.shields.io/github/issues/space-code/flex-ui"></a>
<a href="https://github.com/space-code/flex-ui"><img alt="Number of GitHub issues that are open" src="https://img.shields.io/github/stars/space-code/flex-ui"></a>
<a href="https://github.com/space-code/flex-ui"><img alt="Number of GitHub closed issues" src="https://img.shields.io/github/issues-closed/space-code/flex-ui"></a>
<a href="https://github.com/space-code/flex-ui"><img alt="Number of GitHub stars" src="https://img.shields.io/github/contributors/space-code/flex-ui"></a>
<a href="https://github.com/space-code/flex-ui"><img alt="Number of GitHub pull requests that are open" src="https://img.shields.io/github/issues-pr-raw/space-code/flex-ui"></a>

<a href="https://github.com/space-code/flex-ui"><img alt="GitHub release; latest by date" src="https://img.shields.io/github/v/release/space-code/flex-ui"></a>
<a href="https://github.com/apple/swift-package-manager" alt="flex-ui on Swift Package Manager" title="flex-ui on Swift Package Manager"><img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg" /></a>
</p>
Expand Down
34 changes: 34 additions & 0 deletions Sources/FlexUI/Classes/Core/FlexCompatible.swift
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 {}
20 changes: 20 additions & 0 deletions Sources/FlexUI/Classes/Core/FlexUI.swift
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
}
}
82 changes: 82 additions & 0 deletions Sources/FlexUI/Classes/Extensions/FlexUI+StackView.swift
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
}
}
Loading

0 comments on commit 65bdb5c

Please sign in to comment.