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 issue where negative scale.x values didn't render correctly on iOS 14 #1894

Merged
merged 5 commits into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/Example.xcodeproj/project.pbxproj
Expand Up @@ -435,7 +435,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -465,7 +465,7 @@
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Expand Up @@ -120,7 +120,7 @@ class AnimationPreviewViewController: UIViewController {
private func configureSettingsMenu() {
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "Settings",
image: UIImage(systemName: "repeat.circle")!,
image: UIImage(systemName: "repeat.circle"),
primaryAction: nil,
menu: UIMenu(children: [
UIMenu(
Expand Down
Expand Up @@ -146,17 +146,42 @@ extension CALayer {
},
context: context)

/// iOS 14 and earlier doesn't properly support rendering transforms with
/// negative `scale.x` values: https://github.com/airbnb/lottie-ios/issues/1882
let osSupportsNegativeScaleValues: Bool = {
#if os(iOS) || os(tvOS)
if #available(iOS 15.0, tvOS 15.0, *) {
return true
} else {
return false
}
#else
// We'll assume this works correctly on macOS until told otherwise
return true
#endif
}()

lazy var hasNegativeXScaleValues = transformModel.scale.keyframes.contains(where: { $0.value.x < 0 })

// When `scale.x` is negative, we have to rotate the view
// half way around the y axis to flip it horizontally.
// - We don't do this in snapshot tests because it breaks the tests
// in surprising ways that don't happen at runtime. Definitely not ideal.
// - This isn't supported on iOS 14 and earlier either, so we have to
// log a compatibility error on devices running older OSs.
if TestHelpers.snapshotTestsAreRunning {
if transformModel.scale.keyframes.contains(where: { $0.value.x < 0 }) {
if hasNegativeXScaleValues {
context.logger.warn("""
Negative `scale.x` values are not displayed correctly in snapshot tests
""")
}
} else {
if !osSupportsNegativeScaleValues, hasNegativeXScaleValues {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused how this fixes the issue, isn't this just logging an extra warning?

Copy link
Member Author

@calda calda Jan 4, 2023

Choose a reason for hiding this comment

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

The logCompatibilityIssue and compatibilityAssert methods cause RenderingEngineOption.automatic to detect that the animation is unsupported by the core animation engine and should fall-back to using the main thread rendering engine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, got it!

try context.logCompatibilityIssue("""
iOS 14 and earlier does not support rendering negative `scale.x` values
""")
}

try addAnimation(
for: .rotationY,
keyframes: transformModel.scale.keyframes,
Expand Down
1 change: 1 addition & 0 deletions Tests/Samples/Issues/issue_1882.json

Large diffs are not rendered by default.

@@ -0,0 +1 @@
Supports Core Animation engine
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.