Skip to content

Commit ab4bd9b

Browse files
authored
Merge pull request #69 from RakuyoKit/feature/enhance
Feature/enhance
2 parents 7844468 + f6076db commit ab4bd9b

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

Sources/Core/Extensions/DispatchQueue+RAK.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
extension Extendable where Base: DispatchQueue {
12-
public typealias Task = (_ canceled: Bool) -> Void
12+
public typealias DispatchTask = (_ canceled: Bool) -> Void
1313

1414
/// Create a deferred task that can be canceled midway using the `cancel()` method.
1515
///
@@ -21,15 +21,15 @@ extension Extendable where Base: DispatchQueue {
2121
public static func after(
2222
_ time: DispatchTimeInterval,
2323
execute task: @escaping EmptyClosure
24-
) -> Task? {
24+
) -> DispatchTask? {
2525
func _after(block: @escaping EmptyClosure) {
2626
DispatchQueue.main.asyncAfter(deadline: .now() + time, execute: block)
2727
}
2828

2929
var taskAction: EmptyClosure? = task
30-
var result: Task?
30+
var result: DispatchTask?
3131

32-
let delayedClosure: Task = { canceled in
32+
let delayedClosure: DispatchTask = { canceled in
3333
if let action = taskAction, !canceled {
3434
DispatchQueue.main.async(execute: action)
3535
}
@@ -47,7 +47,7 @@ extension Extendable where Base: DispatchQueue {
4747
/// Cancel delayed tasks
4848
///
4949
/// - Parameter task: Task to be canceled
50-
public static func cancel(_ task: Task?) {
50+
public static func cancel(_ task: DispatchTask?) {
5151
task?(true)
5252
}
5353
}

Sources/Epoxy/Exports.swift

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Make the symbols from each module listed importable with just `import RAKEpoxy`.
2+
@_exported import EpoxyCollectionView
3+
@_exported import EpoxyCore

Sources/Gradient/UIView+Gradient.swift

+26-12
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,40 @@ extension Extendable where Base: UIView {
2323
///
2424
/// - Parameters:
2525
/// - direction: Gradient direction.
26+
/// - forceLayout: Whether to forcefully call `layoutIfNeeded`.
27+
/// Set to `true` in cases where cells are reused; otherwise,
28+
/// it can be determined based on the situation, typically `false`.
2629
/// - colors: The colors for the gradient.
2730
/// - Returns: The created gradient layer.
28-
public func createGradientLayer(direction: Direction, colors: [UIColor]) -> CAGradientLayer {
29-
createGradientLayer(by: .init(direction: direction, colors: .init(colors)))
31+
public func createGradientLayer(direction: Direction, forceLayout: Bool = false, colors: [UIColor]) -> CAGradientLayer {
32+
createGradientLayer(by: .init(direction: direction, colors: .init(colors)), forceLayout: forceLayout)
3033
}
3134

3235
/// Conveniently applies a gradient to the view using preset positions from the `Direction` enumeration.
3336
///
3437
/// - Parameters:
3538
/// - direction: Gradient direction.
39+
/// - forceLayout: Whether to forcefully call `layoutIfNeeded`.
40+
/// Set to `true` in cases where cells are reused; otherwise,
41+
/// it can be determined based on the situation, typically `false`.
3642
/// - colors: The colors for the gradient.
3743
/// - Returns: The created gradient layer.
3844
@discardableResult
39-
public func setGradient(direction: Direction, colors: [UIColor]) -> CAGradientLayer {
40-
applyGradient(with: .init(direction: direction, colors: .init(colors)))
45+
public func setGradient(direction: Direction, forceLayout: Bool = false, colors: [UIColor]) -> CAGradientLayer {
46+
applyGradient(with: .init(direction: direction, colors: .init(colors)), forceLayout: forceLayout)
4147
}
4248
}
4349

4450
extension Extendable where Base: UIView {
45-
/// Creates a gradient layer for the view.
51+
/// Creates a gradient layer for the view
4652
///
47-
/// - Parameter gradient: The gradient configuration.
48-
/// - Returns: The created gradient layer.
49-
public func createGradientLayer(by gradient: Gradient) -> CAGradientLayer {
53+
/// - Parameters:
54+
/// - gradient: Gradient configuration
55+
/// - forceLayout: Whether to forcefully call `layoutIfNeeded`.
56+
/// Set to `true` in cases where cells are reused; otherwise,
57+
/// it can be determined based on the situation, typically `false`.
58+
/// - Returns: The created gradient layer
59+
public func createGradientLayer(by gradient: Gradient, forceLayout: Bool = false) -> CAGradientLayer {
5060
let start = gradient.startPosition
5161
let end = gradient.endPosition
5262

@@ -62,7 +72,7 @@ extension Extendable where Base: UIView {
6272
return layer
6373
}
6474

65-
if base.layer.bounds.isEmpty {
75+
if forceLayout || base.layer.bounds.isEmpty {
6676
base.layoutIfNeeded()
6777
base.superview?.layoutIfNeeded()
6878
}
@@ -80,13 +90,17 @@ extension Extendable where Base: UIView {
8090

8191
/// Applies the gradient configuration to the view.
8292
///
83-
/// - Parameter gradient: The gradient configuration.
93+
/// - Parameters:
94+
/// - gradient: Gradient configuration
95+
/// - forceLayout: Whether to forcefully call `layoutIfNeeded`.
96+
/// Set to `true` in cases where cells are reused; otherwise,
97+
/// it can be determined based on the situation, typically `false`.
8498
/// - Returns: The created gradient layer.
8599
@discardableResult
86-
public func applyGradient(with gradient: Gradient) -> CAGradientLayer {
100+
public func applyGradient(with gradient: Gradient, forceLayout: Bool = false) -> CAGradientLayer {
87101
removeGradientLayer()
88102

89-
let gradientLayer = createGradientLayer(by: gradient)
103+
let gradientLayer = createGradientLayer(by: gradient, forceLayout: forceLayout)
90104

91105
base.layer.insertSublayer(gradientLayer, at: 0)
92106
base.backgroundColor = .clear

0 commit comments

Comments
 (0)