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

(WIP) Support mirror in LottieDrawable. #1557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ public void disableExtraScaleModeInFitXY() {
lottieDrawable.disableExtraScaleModeInFitXY();
}

public void setIsMirror(boolean isMirror) {
lottieDrawable.setIsMirror(isMirror);
}

private void enableOrDisableHardwareLayer() {
int layerType = LAYER_TYPE_SOFTWARE;
switch (renderMode) {
Expand Down
11 changes: 11 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private interface LazyCompositionTask {
private float scale = 1f;
private boolean systemAnimationsEnabled = true;
private boolean safeMode = false;
private boolean isMirror = false;

private final Set<ColorFilterData> colorFilterData = new HashSet<>();
private final ArrayList<LazyCompositionTask> lazyCompositionTasks = new ArrayList<>();
Expand Down Expand Up @@ -321,6 +322,10 @@ public void setSafeMode(boolean safeMode) {
this.safeMode = safeMode;
}

public void setIsMirror(boolean isMirror) {
this.isMirror = isMirror;
}

@Override
public void invalidateSelf() {
if (isDirty) {
Expand Down Expand Up @@ -1173,6 +1178,9 @@ private void drawWithNewAspectRatio(Canvas canvas) {

matrix.reset();
matrix.preScale(scaleX, scaleY);
if (isMirror) {
matrix.preScale(-1, 1, composition.getBounds().width() / 2f, composition.getBounds().height() / 2f);
}
compositionLayer.draw(canvas, matrix, alpha);

if (saveCount > 0) {
Expand Down Expand Up @@ -1218,6 +1226,9 @@ private void drawWithOriginalAspectRatio(Canvas canvas) {

matrix.reset();
matrix.preScale(scale, scale);
if (isMirror) {
matrix.preScale(-1, 1, composition.getBounds().width() / 2f, composition.getBounds().height() / 2f);
}
compositionLayer.draw(canvas, matrix, alpha);

if (saveCount > 0) {
Expand Down