Skip to content
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

Fix parsing issue, add support for DotLottieConfiguration in SwiftUI LottieView #2277

Merged
merged 7 commits into from
Jan 8, 2024

Conversation

calda
Copy link
Member

@calda calda commented Jan 5, 2024

This PR fixes two issues:

  1. Fixes Error when decoding animation "trails_3_s": invalidInput #2269
  2. Fixes Passing DotLottie configuration to LottieView #2228

For #2269, we were failing to parse the animation. It's missing some fields that iOS requires, but that web doesn't require. We can relax the parsing a bit to allow this animation to parse successfully.

When testing the animation after fixing the parsing issue, I ran in to #2228. I bundled that animation and its image assets in a dotLottie file, but it was completely blank because the DotLottieConfiguration.imageProvider was being ignored.

Before #2269 Before fixing #2228 After

@@ -51,6 +51,9 @@ extension LayerModel {
case (.null, _):
return TransformLayer(layerModel: self)

case (.unknown, _):
return nil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes an issue where a layer with an unknown type would log a compatibility error and fall back to the main thread rendering engine, even though the main thread engine wouldn't be able to handle it either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a this comment to the code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also do something about the default case? It seems like without it the compiler would have warned us about this issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I updated this to switch exhaustively

decodedAssets[precompAsset.id] = precompAsset
precompAssets[precompAsset.id] = precompAsset
} else {
let imageAsset = try container.decode(ImageAsset.self)
} else if let imageAsset = try? container.decode(ImageAsset.self) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an image asset fails to parse for some reason, we can recover gracefully instead of throwing an error and rejecting the animation

@@ -8,7 +8,7 @@
// MARK: - InitializableError

enum InitializableError: Error {
case invalidInput
case invalidInput(file: StaticString = #file, line: UInt = #line)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding in file and line context makes it easier to debug where these errors are coming from

@@ -93,7 +93,7 @@ class LayerModel: Codable, DictionaryInitializable {
inFrame = try container.decode(Double.self, forKey: .inFrame)
outFrame = try container.decode(Double.self, forKey: .outFrame)
startTime = try container.decode(Double.self, forKey: .startTime)
transform = try container.decode(Transform.self, forKey: .transform)
transform = try container.decodeIfPresent(Transform.self, forKey: .transform) ?? .default
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the individual properties in a Transform are optional and have default values, so we can easily make the Transform itself optional with a default

/// - Defaults to `[.imageProvider]`
/// - If a component is specified here, that value in the `DotLottieConfiguration`
/// of an active dotLottie animation will override any value provided via other methods.
public func dotLottieConfigurationComponents(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the DotLottieConfiguration overrides any value you pass in via .imageProvider(...), .loopMode(...), or .speed(...), it seems like a good idea to make this behavior configurable. Otherwise it would be impossible to use a custom loop mode or speed when playing some dotLottie animations.

Copy link

emerge-tools bot commented Jan 5, 2024

1 build increased size

Name Version Download Change Install Change
SizeTest
com.airbnb.lottie.sizetest.iOS
1.0 (1) 752.5 kB ⬆️ 5.9 kB (0.79%) 2.3 MB ⬆️ 20.4 kB (0.93%)

SizeTest 1.0 (1)
com.airbnb.lottie.sizetest.iOS

⚖️ Compare build
⏱️ Analyze build performance

Total install size change: ⬆️ 20.4 kB (0.93%)
Total download size change: ⬆️ 5.9 kB (0.79%)

Largest size changes

Item Install Size Change
📝 Lottie.Dictionary.value(for,file,line) ⬆️ 8.2 kB
🗑 Lottie.Dictionary.value(for) ⬇️ -7.2 kB
Strings.Swift File Paths ⬆️ 4.4 kB
📝 Lottie.LottieView.applyCurrentAnimationConfiguration(to) ⬆️ 1.9 kB
DYLD.Fixups ⬆️ 1.3 kB

Image of diff


🛸 Powered by Emerge Tools

Copy link
Contributor

@miguel-jimenez-0529 miguel-jimenez-0529 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -51,6 +51,9 @@ extension LayerModel {
case (.null, _):
return TransformLayer(layerModel: self)

case (.unknown, _):
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also do something about the default case? It seems like without it the compiler would have warned us about this issue.

let precompAsset = try container.decode(PrecompAsset.self)
while
!container.isAtEnd,
let keyContainer = try? containerForKeys.nestedContainer(keyedBy: PrecompAsset.CodingKeys.self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add resilient decoder https://github.com/airbnb/ResilientDecoding in case we need the error at another time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the Codable decoding implementation by default (the dictionary-based implementation is the default in Lottie 4.0+ since it's a lot faster), so no need to invest much in the Codable implementation

Comment on lines -24 to +34
return dotLottieFile.animation()?.animation
return dotLottieFile.animation()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@calda calda enabled auto-merge (squash) January 8, 2024 19:36
@calda calda merged commit 9c1dac7 into master Jan 8, 2024
14 checks passed
@calda calda deleted the cal--2269 branch January 8, 2024 21:03
cgrindel-self-hosted-renovate bot added a commit to cgrindel/rules_swift_package_manager that referenced this pull request Jan 23, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [airbnb/lottie-spm](https://togithub.com/airbnb/lottie-spm) | minor |
`from: "4.3.4"` -> `from: "4.4.0"` |

---

### Release Notes

<details>
<summary>airbnb/lottie-spm (airbnb/lottie-spm)</summary>

###
[`v4.4.0`](https://togithub.com/airbnb/lottie-spm/releases/tag/4.4.0)

[Compare
Source](https://togithub.com/airbnb/lottie-spm/compare/4.3.4...4.4.0)

#### New features

- Add privacy manifest
([airbnb/lottie-ios#2252)
- Codesign Lottie.xcframework
([airbnb/lottie-ios#2259)
- Add time remapping support to Core Animation rendering engine
([airbnb/lottie-ios#2286)
- Add official visionOS support to lottie-ios repo
([airbnb/lottie-ios#2287)
- lottie-spm now supports visionOS
([airbnb/lottie-spm#12)
- Adopt policy on minimum supported Swift / Xcode version, update
minimum versions to Swift 5.7 / Xcode 14.1
([airbnb/lottie-ios#2260)

#### Bug fixes

- Update LottieView to display placeholder using `overlay` instead of
`ZStack`
([airbnb/lottie-ios#2289)
- Fix issue where Core Animation rendering engine couldn't display last
frame of animation when paused
([airbnb/lottie-ios#2254)
- Do not create `DotLottieImageProvider` instance if there's no image
files
([airbnb/lottie-ios#2271)
- Mark DotLottieCache as Sendable
([airbnb/lottie-ios#2245)
- Fix issue where AnimationKeypath in SolidLayer could be incorrect
([airbnb/lottie-ios#2278)
- Fix issue where Repeater could be displayed incorrectly
([airbnb/lottie-ios#2276)
- Include dSYMs in xcframework build
([airbnb/lottie-ios#2284)
- Fix parsing issue, add support for DotLottieConfiguration in SwiftUI
LottieView
([airbnb/lottie-ios#2277)
- Fix issue where DotLottieImageProvider didn't handle base64 images
([airbnb/lottie-ios#2283)
- Fix issue where manually interpolated keyframes could animate
incorrectly
([airbnb/lottie-ios#2285)

**Full Changelog**:
airbnb/lottie-ios@4.3.4...4.4.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
iago849 pushed a commit to atteamapps/lottie-ios that referenced this pull request Feb 8, 2024
MoroziOS pushed a commit to MoroziOS/tmg-lottie-ios that referenced this pull request May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when decoding animation "trails_3_s": invalidInput Passing DotLottie configuration to LottieView
2 participants