forked from avocado-bravocado/lottie-ios
-
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.
Add support for rounded corners to Main Thread rendering engine (airb…
- Loading branch information
1 parent
b694c28
commit dacef6a
Showing
24 changed files
with
315 additions
and
0 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
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
81 changes: 81 additions & 0 deletions
81
Sources/Private/MainThread/NodeRenderSystem/Nodes/ModifierNodes/RoundedCornersNode.swift
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,81 @@ | ||
// | ||
// RoundedCornersNode.swift | ||
// Lottie | ||
// | ||
// Created by Duolingo on 10/31/22. | ||
// | ||
|
||
import Foundation | ||
import QuartzCore | ||
|
||
// MARK: - RoundedCornersProperties | ||
|
||
final class RoundedCornersProperties: NodePropertyMap, KeypathSearchable { | ||
|
||
// MARK: Lifecycle | ||
|
||
init(roundedCorners: RoundedCorners) { | ||
keypathName = roundedCorners.name | ||
radius = NodeProperty(provider: KeyframeInterpolator(keyframes: roundedCorners.radius.keyframes)) | ||
keypathProperties = ["Radius" : radius] | ||
properties = Array(keypathProperties.values) | ||
} | ||
|
||
// MARK: Internal | ||
|
||
let keypathProperties: [String: AnyNodeProperty] | ||
let properties: [AnyNodeProperty] | ||
let keypathName: String | ||
|
||
let radius: NodeProperty<LottieVector1D> | ||
} | ||
|
||
// MARK: - RoundedCornersNode | ||
|
||
final class RoundedCornersNode: AnimatorNode { | ||
|
||
// MARK: Lifecycle | ||
|
||
init(parentNode: AnimatorNode?, roundedCorners: RoundedCorners, upstreamPaths: [PathOutputNode]) { | ||
outputNode = PassThroughOutputNode(parent: parentNode?.outputNode) | ||
self.parentNode = parentNode | ||
properties = RoundedCornersProperties(roundedCorners: roundedCorners) | ||
self.upstreamPaths = upstreamPaths | ||
} | ||
|
||
// MARK: Internal | ||
|
||
let properties: RoundedCornersProperties | ||
|
||
let parentNode: AnimatorNode? | ||
let outputNode: NodeOutput | ||
var hasLocalUpdates = false | ||
var hasUpstreamUpdates = false | ||
var lastUpdateFrame: CGFloat? = nil | ||
var isEnabled = true | ||
|
||
// MARK: Animator Node | ||
var propertyMap: NodePropertyMap & KeypathSearchable { | ||
properties | ||
} | ||
|
||
func forceUpstreamOutputUpdates() -> Bool { | ||
hasLocalUpdates || hasUpstreamUpdates | ||
} | ||
|
||
func rebuildOutputs(frame: CGFloat) { | ||
for pathContainer in upstreamPaths { | ||
let pathObjects = pathContainer.removePaths(updateFrame: frame) | ||
for path in pathObjects { | ||
pathContainer.appendPath( | ||
path.roundCorners( | ||
radius: properties.radius.value.cgFloatValue), | ||
updateFrame: frame) | ||
} | ||
} | ||
} | ||
|
||
// MARK: Fileprivate | ||
|
||
fileprivate let upstreamPaths: [PathOutputNode] | ||
} |
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,47 @@ | ||
// | ||
// RoundedCorners.swift | ||
// Lottie | ||
// | ||
// Created by Duolingo on 10/31/22. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - RoundedCorners | ||
|
||
final class RoundedCorners: ShapeItem { | ||
|
||
// MARK: Lifecycle | ||
|
||
required init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: RoundedCorners.CodingKeys.self) | ||
radius = try | ||
container.decode( | ||
KeyframeGroup<LottieVector1D>.self, | ||
forKey: .radius) | ||
try super.init(from: decoder) | ||
} | ||
|
||
required init(dictionary: [String: Any]) throws { | ||
let radiusDictionary: [String: Any] = try dictionary.value(for: CodingKeys.radius) | ||
radius = try KeyframeGroup<LottieVector1D>(dictionary: radiusDictionary) | ||
try super.init(dictionary: dictionary) | ||
} | ||
|
||
// MARK: Internal | ||
|
||
/// The radius of rounded corners | ||
let radius: KeyframeGroup<LottieVector1D> | ||
|
||
override func encode(to encoder: Encoder) throws { | ||
try super.encode(to: encoder) | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(radius, forKey: .radius) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case radius = "r" | ||
} | ||
} |
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
Oops, something went wrong.