Skip to content

Commit

Permalink
Blend mode support (#1585)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal Stephens <[email protected]>
  • Loading branch information
k-o-d-e-n and calda authored May 25, 2022
1 parent 1344b88 commit da9eaaa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Lottie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@
6DB3BDC328245AA2002A276D /* ParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3BDBF28245A6A002A276D /* ParsingTests.swift */; };
6DEF696E2824A76C007D640F /* BundleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DEF696D2824A76C007D640F /* BundleTests.swift */; };
A1D5BAAC27C731A500777D06 /* DataURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1D5BAAB27C731A500777D06 /* DataURLTests.swift */; };
A40460592832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */; };
A404605A2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */; };
A404605B2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -777,6 +780,7 @@
6DB3BDBF28245A6A002A276D /* ParsingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParsingTests.swift; sourceTree = "<group>"; };
6DEF696D2824A76C007D640F /* BundleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleTests.swift; sourceTree = "<group>"; };
A1D5BAAB27C731A500777D06 /* DataURLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataURLTests.swift; sourceTree = "<group>"; };
A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BlendMode+Filter.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1258,6 +1262,7 @@
2E9C95C02822F43100677516 /* Extensions */ = {
isa = PBXGroup;
children = (
A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */,
2E9C95C12822F43100677516 /* CGFloatExtensions.swift */,
2E9C95C22822F43100677516 /* CGColor+RGB.swift */,
2E9C95C32822F43100677516 /* AnimationKeypathExtension.swift */,
Expand Down Expand Up @@ -1830,6 +1835,7 @@
2EAF5AE027A0798700E00531 /* Keyframe.swift in Sources */,
2E9C960F2822F43100677516 /* Animation.swift in Sources */,
2E9C969C2822F43100677516 /* StarNode.swift in Sources */,
A40460592832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */,
2E9C96542822F43100677516 /* ImageCompositionLayer.swift in Sources */,
2EAF5AB327A0798700E00531 /* AnimationImageProvider.swift in Sources */,
2E9C95F12822F43100677516 /* GradientStroke.swift in Sources */,
Expand Down Expand Up @@ -2037,6 +2043,7 @@
2EAF5AE127A0798700E00531 /* Keyframe.swift in Sources */,
2E9C96102822F43100677516 /* Animation.swift in Sources */,
2E9C969D2822F43100677516 /* StarNode.swift in Sources */,
A404605A2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */,
2E9C96552822F43100677516 /* ImageCompositionLayer.swift in Sources */,
2EAF5AB427A0798700E00531 /* AnimationImageProvider.swift in Sources */,
2E9C95F22822F43100677516 /* GradientStroke.swift in Sources */,
Expand Down Expand Up @@ -2224,6 +2231,7 @@
2EAF5AE227A0798700E00531 /* Keyframe.swift in Sources */,
2E9C96112822F43100677516 /* Animation.swift in Sources */,
2E9C969E2822F43100677516 /* StarNode.swift in Sources */,
A404605B2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */,
2E9C96562822F43100677516 /* ImageCompositionLayer.swift in Sources */,
2EAF5AB527A0798700E00531 /* AnimationImageProvider.swift in Sources */,
2E9C95F32822F43100677516 /* GradientStroke.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BaseCompositionLayer: BaseAnimationLayer {
super.init()

setupSublayers()
compositingFilter = layerModel.blendMode.filterName
name = layerModel.name
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CompositionLayer: CALayer, KeypathSearchable {
"sublayerTransform" : NSNull(),
"hidden" : NSNull(),
]
compositingFilter = layer.blendMode.filterName
addSublayer(contentsLayer)

if let maskLayer = maskLayer {
Expand Down
31 changes: 31 additions & 0 deletions Sources/Private/Utility/Extensions/BlendMode+Filter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// File.swift
//
//
// Created by Denis Koryttsev on 10.05.2022.
//

extension BlendMode {
/// The Core Image filter name for this `BlendMode`, that can be applied to a `CALayer`'s `compositingFilter`.
/// Supported compositing filters are defined here: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP30000136-SW71
var filterName: String? {
switch self {
case .normal: return nil
case .multiply: return "multiplyBlendMode"
case .screen: return "screenBlendMode"
case .overlay: return "overlayBlendMode"
case .darken: return "darkenBlendMode"
case .lighten: return "lightenBlendMode"
case .colorDodge: return "colorDodgeBlendMode"
case .colorBurn: return "colorBurnBlendMode"
case .hardLight: return "hardLightBlendMode"
case .softLight: return "softLightBlendMode"
case .difference: return "differenceBlendMode"
case .exclusion: return "exclusionBlendMode"
case .hue: return "hueBlendMode"
case .saturation: return "saturationBlendMode"
case .color: return "colorBlendMode"
case .luminosity: return "luminosityBlendMode"
}
}
}
1 change: 1 addition & 0 deletions Tests/Samples/Nonanimating/blend_mode_test.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Tests/SnapshotConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension SnapshotConfiguration {
"Issues/issue_1407": .precision(0.9),
"Nonanimating/FirstText": .precision(0.99),
"Nonanimating/verifyLineHeight": .precision(0.99),
"Nonanimating/blend_mode_test": .precision(0.99),

/// Test cases for the `AnimationKeypath` / `AnyValueProvider` system
"Nonanimating/keypathTest": .customValueProviders([
Expand Down

0 comments on commit da9eaaa

Please sign in to comment.