Skip to content

Commit

Permalink
Merge pull request #62 from RakuyoKit/feature/2024-07-23
Browse files Browse the repository at this point in the history
Feature/2024 07 23
  • Loading branch information
rakuyoMo authored Jul 24, 2024
2 parents 424f9f9 + 9f108f0 commit 99f4feb
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 74 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/GRDB.swift.git",
"state" : {
"revision" : "78448cf8f4ed39b259bd6718d074a57ae3b2e8ba",
"version" : "6.28.0"
"revision" : "1cd6c7cbffa7ecac14a8a7c0f27d5c3e7c35c87e",
"version" : "6.29.0"
}
},
{
Expand All @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.8.2"),
.package(url: "https://github.com/airbnb/epoxy-ios.git", from: "0.10.0"),
.package(url: "https://github.com/groue/GRDB.swift.git", from: "6.28.0"),
.package(url: "https://github.com/groue/GRDB.swift.git", from: "6.29.0"),
.package(url: "https://github.com/RakuyoKit/RaLog.git", from: "1.7.4"),
.package(url: "https://github.com/devxoul/Then.git", from: "3.0.0"),
],
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Extensions/ContentMode+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RakuyoKit
//
// Created by Rakuyo on 2024/6/12.
// Copyright © 2024 LenticularStickers. All rights reserved.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import UIKit
Expand Down
23 changes: 17 additions & 6 deletions Sources/Core/Extensions/Date+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@ extension Extendable where Base == Date {
/// Start time of the specified date
public var start: Date { calendar.startOfDay(for: base) }

/// Timestamp for N days in the future
public func apply(day: Int) -> Date? {
calendar.date(byAdding: .day, value: day, to: base)
/// Increment or decrement `value` on `component` based on the current time.
///
/// A positive value represents the future, and a negative value represents the past.
public func apply(value: Int, by component: Calendar.Component) -> Date? {
calendar.date(byAdding: component, value: value, to: base)
}

/// Timestamp for N years in the future
public func apply(year: Int) -> Date? {
calendar.date(byAdding: .year, value: year, to: base)
/// Increment or decrement `value` on `.second` based on the current time.
///
/// A positive value represents the future, and a negative value represents the past.
public func apply(second value: Int) -> Date? {
apply(value: value, by: .second)
}

/// Increment or decrement `value` on `.day` based on the current time.
///
/// A positive value represents the future, and a negative value represents the past.
public func apply(day value: Int) -> Date? {
apply(value: value, by: .day)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Core/Extensions/UIRectCorner+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import UIKit
extension UIRectCorner: NamespaceProviding { }

extension Extendable where Base == UIRectCorner {
public static var top: Self {
Base([.topLeft, .topRight]).rak
public static var top: Base {
.init([.topLeft, .topRight])
}

public static var bottom: Self {
Base([.bottomLeft, .bottomRight]).rak
public static var bottom: Base {
.init([.bottomLeft, .bottomRight])
}
}
2 changes: 1 addition & 1 deletion Sources/Epoxy/Row/ImageRow/AnyImageContent+Accessory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RakuyoKit
//
// Created by Rakuyo on 2024/7/8.
// Copyright © 2024 LenticularStickers. All rights reserved.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

#if !os(watchOS)
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRDB/CodableRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RakuyoKit
//
// Created by Rakuyo on 2024/5/7.
// Copyright © 2024 LenticularStickers. All rights reserved.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRDB/PersistableRecord+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RakuyoKit
//
// Created by Rakuyo on 2024/5/7.
// Copyright © 2024 LenticularStickers. All rights reserved.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRDB/QueryInterfaceRequest+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RakuyoKit
//
// Created by Rakuyo on 2024/5/9.
// Copyright © 2024 LenticularStickers. All rights reserved.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Gradient/Gradient+Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import RAKCore

extension Gradient {
/// Wrapper for an array of gradient colors
public struct Colors {
public struct Colors: Hashable {
/// Array of colors
public let colors: [UIColor]

Expand Down
63 changes: 38 additions & 25 deletions Sources/Gradient/Gradient+Direction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,54 @@
// Gradient+Direction.swift
// RakuyoKit
//
// Created by Rakuyo on 2024/4/10.
// Created by Rakuyo on 2024/7/23.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import UIKit
import Foundation

// MARK: - Gradient.Direction

extension Gradient {
/// Specifies the direction of colors during gradient rendering.
/// This type can be said to be a further abstraction of `Gradient.Position`
///
/// The values of this enumeration are set not according to the documentation of `startPoint`,
/// but rather determined by **visual perception**.
///
/// For example, if our color array is `[.red, .black, .green]` and the direction is set to `from .top to .bottom`,
/// the effect would be: red appears at the top of the view, and green appears at the bottom of the view.
public struct Direction {
public let x: CGFloat

public let y: CGFloat

public init(x: CGFloat, y: CGFloat) {
self.x = x
self.y = y
}
/// `Gradient.Position` represents a specific point or position.
/// The type `Gradient.Direction` represents the direction, including the starting point and the end point.
public enum Direction: Hashable {
case topToBottom
case bottomToTop
case leftToRight
case rightToLeft
case topLeftToBottomRight
case topRightToBottomLeft
case bottomLeftToTopRight
case bottomRightToTopLeft
case custom(from: Position, to: Position)
}
}

extension Gradient.Direction {
public static var top: Self { .init(x: 0.5, y: 0.0) }
public static var bottom: Self { .init(x: 0.5, y: 1.0) }
public static var left: Self { .init(x: 0.0, y: 0.5) }
public static var right: Self { .init(x: 1.0, y: 0.5) }
public static var topLeft: Self { .init(x: 0.0, y: 0.0) }
public static var topRight: Self { .init(x: 1.0, y: 0.0) }
public static var bottomLeft: Self { .init(x: 0.0, y: 1.0) }
public static var bottomRight: Self { .init(x: 1.0, y: 1.0) }
/// The starting and ending points corresponding to the direction
public var positions: (start: Gradient.Position, end: Gradient.Position) {
switch self {
case .topToBottom:
(.top, .bottom)
case .bottomToTop:
(.bottom, .top)
case .leftToRight:
(.left, .right)
case .rightToLeft:
(.right, .left)
case .topLeftToBottomRight:
(.topLeft, .bottomRight)
case .topRightToBottomLeft:
(.topRight, .bottomLeft)
case .bottomLeftToTopRight:
(.bottomLeft, .topRight)
case .bottomRightToTopLeft:
(.bottomRight, .topLeft)
case .custom(let from, let to):
(from, to)
}
}
}
42 changes: 42 additions & 0 deletions Sources/Gradient/Gradient+Position.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Gradient+Position.swift
// RakuyoKit
//
// Created by Rakuyo on 2024/4/10.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import UIKit

// MARK: - Gradient.Position

extension Gradient {
/// Specifies the position of colors during gradient rendering.
///
/// The values of this enumeration are set not according to the documentation of `startPoint`,
/// but rather determined by **visual perception**.
///
/// For example, if our color array is `[.red, .black, .green]` and the position is set to `from .top to .bottom`,
/// the effect would be: red appears at the top of the view, and green appears at the bottom of the view.
public struct Position: Hashable {
public let x: CGFloat

public let y: CGFloat

public init(x: CGFloat, y: CGFloat) {
self.x = x
self.y = y
}
}
}

extension Gradient.Position {
public static let top = Self(x: 0.5, y: 0.0)
public static let bottom = Self(x: 0.5, y: 1.0)
public static let left = Self(x: 0.0, y: 0.5)
public static let right = Self(x: 1.0, y: 0.5)
public static let topLeft = Self(x: 0.0, y: 0.0)
public static let topRight = Self(x: 1.0, y: 0.0)
public static let bottomLeft = Self(x: 0.0, y: 1.0)
public static let bottomRight = Self(x: 1.0, y: 1.0)
}
21 changes: 13 additions & 8 deletions Sources/Gradient/Gradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
import UIKit

/// Gradient configuration
public struct Gradient {
public struct Gradient: Hashable {
/// Starting position of the gradient
public let startDirection: Direction
public let startPosition: Position

/// Ending position of the gradient
public let endDirection: Direction
public let endPosition: Position

/// Gradient colors
public let colors: Colors

public init(start: Direction, end: Direction, colors: Colors) {
startDirection = start
endDirection = end
public init(start: Position, end: Position, colors: Colors) {
startPosition = start
endPosition = end
self.colors = colors
}

public init(direction: Direction, colors: Colors) {
let positions = direction.positions
self.init(start: positions.start, end: positions.end, colors: colors)
}
}
35 changes: 15 additions & 20 deletions Sources/Gradient/UIView+Gradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,31 @@ import RAKCore
import Then

extension Extendable where Base: UIView {
/// Specifies the direction of colors during gradient rendering.
/// This type can be said to be a further abstraction of `Gradient.Position`
///
/// The values of this enumeration are set not according to the documentation of `startPoint`,
/// but rather determined by **visual perception**.
///
/// For example, if our color array is `[.red, .black, .green]` and the direction is set to `from .top to .bottom`,
/// the effect would be: red appears at the top of the view, and green appears at the bottom of the view.
/// `Gradient.Position` represents a specific point or position.
/// The type `Gradient.Direction` represents the direction, including the starting point and the end point.
public typealias Direction = Gradient.Direction
/// Conveniently creates a gradient layer using preset directions from the `Direction` enumeration.

/// Conveniently creates a gradient layer using preset positions from the `Direction` enumeration.
///
/// - Parameters:
/// - start: The start direction.
/// - end: The end direction.
/// - direction: Gradient direction.
/// - colors: The colors for the gradient.
/// - Returns: The created gradient layer.
public func createGradientLayer(from start: Direction, to end: Direction, colors: [UIColor]) -> CAGradientLayer {
createGradientLayer(by: .init(start: start, end: end, colors: .init(colors)))
public func createGradientLayer(direction: Direction, colors: [UIColor]) -> CAGradientLayer {
createGradientLayer(by: .init(direction: direction, colors: .init(colors)))
}

/// Conveniently applies a gradient to the view using preset directions from the `Direction` enumeration.
/// Conveniently applies a gradient to the view using preset positions from the `Direction` enumeration.
///
/// - Parameters:
/// - start: The start direction.
/// - end: The end direction.
/// - direction: Gradient direction.
/// - colors: The colors for the gradient.
/// - Returns: The created gradient layer.
@discardableResult
public func setGradientFrom(_ start: Direction, to end: Direction, colors: [UIColor]) -> CAGradientLayer {
applyGradient(with: .init(start: start, end: end, colors: .init(colors)))
public func setGradient(direction: Direction, colors: [UIColor]) -> CAGradientLayer {
applyGradient(with: .init(direction: direction, colors: .init(colors)))
}
}

Expand All @@ -52,9 +47,9 @@ extension Extendable where Base: UIView {
/// - Parameter gradient: The gradient configuration.
/// - Returns: The created gradient layer.
public func createGradientLayer(by gradient: Gradient) -> CAGradientLayer {
let start = gradient.startDirection
let end = gradient.endDirection
let start = gradient.startPosition
let end = gradient.endPosition

let layer = CAGradientLayer()

guard
Expand Down

0 comments on commit 99f4feb

Please sign in to comment.