-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to TextProviders
for CoreAnimation
#1723
Changes from all commits
5436bf7
ba40ed1
f4fe478
ae4e887
2632390
b542f66
01307aa
5055f10
a053713
31f3bf9
7a71e9a
c8a84c2
c7a21ce
ff77091
77bb6ba
8cb4ccd
8bbf3c9
1d50bef
913e1da
de65cbb
b2309b6
8be6a68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ struct SnapshotConfiguration { | |
/// A custom `AnimationImageProvider` to use when rendering this animation | ||
var customImageProvider: AnimationImageProvider? | ||
|
||
/// A custom `AnimationTextProvider` to use when rendering this animation | ||
var customTextProvider: AnimationTextProvider? | ||
|
||
/// A custom `AnimationFontProvider` to use when rendering this animation | ||
var customFontProvider: AnimationFontProvider? | ||
|
||
|
@@ -70,6 +73,9 @@ extension SnapshotConfiguration { | |
// Test cases for `AnimatedImageProvider` | ||
"Nonanimating/_dog": .customImageProvider(HardcodedImageProvider(imageName: "Samples/Images/dog.png")), | ||
|
||
// Test cases for `AnimatedTextProvider` | ||
"Issues/issue_1722": .customTextProvider(HardcodedTextProvider(text: "Bounce-bounce")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you're done with the code changes you can generate the snapshot images for this by running the unit test target on an iPhone 8 simulator (or by running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi I think the snapshot tests are sensitive to specific Xcode versions -- right now I think they run correctly on Xcode 13.4.1 but not on Xcode 14. If you get a lot of spurious failures when you run the tests let me know and I can pull you branch and run them for you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm unfortunately it always return this message during the test run: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, Cal, that would be helpful, thanks a bunch! ππΌ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way the name of the text layer in the provided animation is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is expected the first time you run the tests after you add a new sample JSON file. If you run the tests again this goes away, since now it compares the new snapshot with the previously-recorded one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm true. However, the snapshots anyway don't contain the text. Could it be because the text layer has a different name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was because we had to call |
||
|
||
// Test cases for `AnimationFontProvider` | ||
"Nonanimating/Text_Glyph": .customFontProvider(HardcodedFontProvider(font: UIFont(name: "Chalkduster", size: 36)!)), | ||
|
||
|
@@ -128,6 +134,15 @@ extension SnapshotConfiguration { | |
return configuration | ||
} | ||
|
||
static func customTextProvider( | ||
_ customTextProvider: AnimationTextProvider) | ||
-> SnapshotConfiguration | ||
{ | ||
var configuration = SnapshotConfiguration.default | ||
configuration.customTextProvider = customTextProvider | ||
return configuration | ||
} | ||
|
||
/// A `SnapshotConfiguration` value using the given custom value providers | ||
static func customFontProvider( | ||
_ customFontProvider: AnimationFontProvider) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Created by Igor Katselenbogen on 08/19/22. | ||
// Copyright Β© 2022 Airbnb Inc. All rights reserved. | ||
|
||
import Lottie | ||
|
||
// MARK: - HardcodedTextProvider | ||
|
||
/// An `AnimationTextProvider` that always returns a specific hardcoded text | ||
class HardcodedTextProvider: AnimationTextProvider { | ||
|
||
// MARK: Lifecycle | ||
|
||
init(text: String) { | ||
self.text = text | ||
} | ||
|
||
// MARK: Internal | ||
|
||
func textFor(keypathName _: String, sourceText _: String) -> String { | ||
text | ||
} | ||
|
||
// MARK: Private | ||
|
||
private let text: String | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Supports Core Animation engine |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Does not support Core Animation engine. Encountered compatibility issues: | ||
[TEXT] The Core Animation rendering engine does not support animating multiple keyframes for text layer text values (due to limitations of Core Animation `CAKeyframeAnimation`s). | ||
[TEXT] The Core Animation rendering engine does not support animating multiple keyframes for text layer text values (due to limitations of Core Animation `CAKeyframeAnimation`s). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Does not support Core Animation engine. Encountered compatibility issues: | ||
[TEXT] The Core Animation rendering engine does not support animating multiple keyframes for text layer text values (due to limitations of Core Animation `CAKeyframeAnimation`s). | ||
[TEXT] The Core Animation rendering engine does not support animating multiple keyframes for text layer text values (due to limitations of Core Animation `CAKeyframeAnimation`s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to actually apply this text provider to the
AnimationView
inSnapshotConfiguration.makeAnimationView
: https://github.com/airbnb/lottie-ios/blob/master/Tests/SnapshotTests.swift#L255There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool to know, thanks!
Done in c7a21ce β