Skip to content

Commit

Permalink
Release 11.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-divkit committed Oct 18, 2022
1 parent 0242075 commit 334a34a
Show file tree
Hide file tree
Showing 120 changed files with 1,556 additions and 275 deletions.
1 change: 1 addition & 0 deletions Core/Base/Alignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CoreGraphics
import BaseUI

/// Determines postioning of child item inside parent container
@frozen
public enum Alignment {
/// Child items are laid out starting from top/left
case leading
Expand Down
2 changes: 0 additions & 2 deletions Core/Base/Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public enum Combine {
}

public struct CombineFailure<T>: Error, CustomDebugStringConvertible {
@usableFromInline
let values: [T]

@inlinable
public init(values: [T]) {
self.values = values
}
Expand Down
1 change: 1 addition & 0 deletions Core/Base/Either.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Foundation

@frozen
public enum Either<T, U> {
case left(T)
case right(U)
Expand Down
62 changes: 56 additions & 6 deletions Core/Base/Gradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CoreGraphics

import BaseUI

@frozen
public enum Gradient: Equatable {
public typealias Point = (color: Color, location: CGFloat)

Expand Down Expand Up @@ -53,27 +54,75 @@ public enum Gradient: Equatable {
}

public struct Radial: Equatable {
public let center: RelativePoint
public let end: RelativePoint
public let centerX: CenterPoint
public let centerY: CenterPoint
public let end: Radius
public let centerColor: Color
public let intermediatePoints: [Point]
public let outerColor: Color
public let shape: Shape

public init(
center: RelativePoint = .mid,
end: RelativePoint? = nil,
centerColor: Color,
intermediatePoints: [Point] = [],
outerColor: Color? = nil,
shape: Shape? = nil
) {
let positions = intermediatePoints.map { $0.location }
assert(positions == positions.sorted())

self.centerX = .relative(center.x)
self.centerY = .relative(center.y)
self.end = .relativeToSize(end ?? RelativeRect.full.radialEndPoint(for: center))
self.centerColor = centerColor
self.intermediatePoints = intermediatePoints
self.outerColor = outerColor ?? centerColor.withAlphaComponent(0)
self.shape = shape ?? .ellipse
}

public init(
centerX: CenterPoint,
centerY: CenterPoint,
end: Radius,
centerColor: Color,
intermediatePoints: [Point] = [],
outerColor: Color? = nil
) {
let positions = intermediatePoints.map { $0.location }
assert(positions == positions.sorted())

self.center = center
self.end = end ?? RelativeRect.full.radialEndPoint(for: center)
self.centerX = centerX
self.centerY = centerY
self.end = end
self.centerColor = centerColor
self.intermediatePoints = intermediatePoints
self.outerColor = outerColor ?? centerColor.withAlphaComponent(0)
self.shape = .circle
}

public enum CenterPoint: Equatable {
case relative(CGFloat)
case absolute(Int)
}

public enum Radius: Equatable {
case relativeToBorders(RelativeToBorder)
case relativeToSize(RelativePoint)
case absolute(Int)

public enum RelativeToBorder {
case nearestCorner
case farthestCorner
case nearestSide
case farthestSide
}
}

public enum Shape {
case circle
case ellipse
}
}

Expand Down Expand Up @@ -111,7 +160,8 @@ extension Gradient.Linear {

extension Gradient.Radial {
public static func ==(lhs: Gradient.Radial, rhs: Gradient.Radial) -> Bool {
lhs.center == rhs.center
lhs.centerX == rhs.centerX
&& lhs.centerY == rhs.centerY
&& lhs.end == rhs.end
&& lhs.centerColor == rhs.centerColor
&& lhs.intermediatePoints == rhs.intermediatePoints
Expand Down Expand Up @@ -152,7 +202,7 @@ extension Gradient.Radial: CustomDebugStringConvertible {
path.append(centerColor.debugDescription)
path += intermediatePoints.map { "(\($0.location):\($0.color.debugDescription)" }
path.append(outerColor.debugDescription)
return "Radial c: \(center), \(path.joined(separator: ".."))"
return "Radial c: \(centerX), \(centerY), \(path.joined(separator: ".."))"
}
}

Expand Down
1 change: 1 addition & 0 deletions Core/Base/ImagePlaceholder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import BaseUI

@frozen
public enum ImagePlaceholder: Equatable, CustomDebugStringConvertible {
case image(Image)
case color(Color)
Expand Down
1 change: 0 additions & 1 deletion Core/Base/Observer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
public struct Observer<T> {
public let action: (T) -> Void

@inlinable
public init(action: @escaping (T) -> Void) {
self.action = action
}
Expand Down
88 changes: 86 additions & 2 deletions Core/Base/RadialGradientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,91 @@ public final class RadialGradientView: UIView {
+ [gradient.outerColor.cgColor]
gradientLayer.locations =
([0] + gradient.intermediatePoints.map { $0.location } + [1]) as [NSNumber]
gradientLayer.startPoint = gradient.center.rawValue
gradientLayer.endPoint = gradient.end.rawValue

}

public override func layoutSubviews() {
super.layoutSubviews()
gradientLayer.startPoint = startPoint
gradientLayer.endPoint = endPoint
}

private var startPoint: CGPoint {
let centerX: CGFloat
switch gradient.centerX {
case let .relative(x):
centerX = x
case let .absolute(x):
centerX = CGFloat(x) / bounds.width
}
let centerY: CGFloat
switch gradient.centerY {
case let .relative(y):
centerY = y
case let .absolute(y):
centerY = CGFloat(y) / bounds.height
}
return CGPoint(x: centerX, y: centerY)
}

private var endPoint: CGPoint {
let startPoint = startPoint
let maxSize = max(bounds.width, bounds.height)
let kx = maxSize / bounds.width
let ky = maxSize / bounds.height
switch gradient.end {
case let .relativeToBorders(relativeRaduis):
let radius: CGFloat
switch relativeRaduis {
case .nearestSide:
if startPoint.x.isOnBorder || startPoint.y.isOnBorder {
return CGPoint(x: startPoint.x + .ulpOfOne, y: startPoint.y + .ulpOfOne)
}
radius = min(startPoint.x.nearestDistance / kx, startPoint.y.nearestDistance / ky)
case .nearestCorner:
if startPoint.x.isOnBorder && startPoint.y.isOnBorder {
return CGPoint(x: startPoint.x + .ulpOfOne, y: startPoint.y + .ulpOfOne)
}
radius = sqrt(pow(startPoint.x.nearestDistance / kx, 2) + pow(startPoint.y.nearestDistance / ky, 2))
case .farthestCorner:
radius = sqrt(pow(startPoint.x.farthestDistance / kx, 2) + pow(startPoint.y.farthestDistance / ky, 2))
case .farthestSide:
radius = max(startPoint.x.farthestDistance / kx, startPoint.y.farthestDistance / ky)
}
return CGPoint(x: startPoint.x + radius * kx, y: startPoint.y + radius * ky)
case let .relativeToSize(point):
switch gradient.shape {
case .ellipse:
return point.rawValue
case .circle:
return CGPoint(x: point.x * kx, y: point.y * ky)
}
case let .absolute(radius):
let x = CGFloat(radius) / bounds.width + startPoint.x
let y = CGFloat(radius) / bounds.height + startPoint.y
return CGPoint(x: x, y: y)
}
}
}

fileprivate extension CGFloat {
var nearest: CGFloat {
self < 0.5 ? 0 : 1
}

var farthest: CGFloat {
self > 0.5 ? 0 : 1
}

var nearestDistance: CGFloat {
abs(self.nearest - self)
}

var farthestDistance: CGFloat {
abs(self.farthest - self)
}

var isOnBorder: Bool {
self == 0 || self == 1
}
}
1 change: 0 additions & 1 deletion Core/Base/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public struct Signal<T> {
addObserver(Observer(action: action))
}

@inlinable
public init(addObserver: @escaping (Observer<T>) -> Disposable) {
self.addObserver = addObserver
}
Expand Down
1 change: 0 additions & 1 deletion Core/BaseTiny/Tagged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public struct Tagged<Tag, RawValue>: RawRepresentable {
public var rawValue: RawValue

@inlinable
public init(rawValue: RawValue) {
self.rawValue = rawValue
}
Expand Down
1 change: 1 addition & 0 deletions Core/BaseUI/FontSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum FontFamily: Hashable {
case YSDisplay
}

@frozen
public enum FontWeight: Hashable {
case light
case regular
Expand Down
31 changes: 31 additions & 0 deletions Core/CommonCore/ImageViewProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 Yandex LLC. All rights reserved.

import UIKit

public protocol ImageViewProtocol {
var appearanceAnimation: ImageViewAnimation? { get set }
var imageRedrawingColor: Color? { get set }
var imageContentMode: ImageContentMode { get set }
}

public struct ImageViewAnimation {
let duration: Double
let delay: Double
let startAlpha: Double
let endAlpha: Double
let options: UIView.AnimationOptions

public init(
duration: Double,
delay: Double,
startAlpha: Double,
endAlpha: Double,
options: UIView.AnimationOptions
) {
self.duration = duration
self.delay = delay
self.startAlpha = startAlpha
self.endAlpha = endAlpha
self.options = options
}
}
2 changes: 1 addition & 1 deletion Core/CommonCore/ObjectsReusability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Foundation

@frozen
public enum ModelReusability<Object> {
case orphan
case hasReusableObject(Object)
Expand All @@ -11,7 +12,6 @@ public struct ReuseResult<Object, Model> {
public let modelsReusability: [(Model, ModelReusability<Object>)]
public let orphanObjects: [Object]

@inlinable
public init(modelsReusability: [(Model, ModelReusability<Object>)], orphanObjects: [Object]) {
self.modelsReusability = modelsReusability
self.orphanObjects = orphanObjects
Expand Down
Loading

0 comments on commit 334a34a

Please sign in to comment.