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

Pass LottieComposition to all content when it is generated #2167

Merged
merged 1 commit into from
Nov 14, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Pass LottieComposition to all content when it is generated
  • Loading branch information
gpeal committed Nov 12, 2022
commit 1afeb86238f9aa47aa72aff778f6a31817a0678f
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.LPaint;
import com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation;
Expand All @@ -30,11 +31,11 @@ public class ContentGroup implements DrawingContent, PathContent,
private final Paint offScreenPaint = new LPaint();
private final RectF offScreenRectF = new RectF();

private static List<Content> contentsFromModels(LottieDrawable drawable, BaseLayer layer,
private static List<Content> contentsFromModels(LottieDrawable drawable, LottieComposition composition, BaseLayer layer,
List<ContentModel> contentModels) {
List<Content> contents = new ArrayList<>(contentModels.size());
for (int i = 0; i < contentModels.size(); i++) {
Content content = contentModels.get(i).toContent(drawable, layer);
Content content = contentModels.get(i).toContent(drawable, composition, layer);
if (content != null) {
contents.add(content);
}
Expand Down Expand Up @@ -63,9 +64,9 @@ private static List<Content> contentsFromModels(LottieDrawable drawable, BaseLay
@Nullable private List<PathContent> pathContents;
@Nullable private TransformKeyframeAnimation transformAnimation;

public ContentGroup(final LottieDrawable lottieDrawable, BaseLayer layer, ShapeGroup shapeGroup) {
public ContentGroup(final LottieDrawable lottieDrawable, BaseLayer layer, ShapeGroup shapeGroup, LottieComposition composition) {
this(lottieDrawable, layer, shapeGroup.getName(),
shapeGroup.isHidden(), contentsFromModels(lottieDrawable, layer, shapeGroup.getItems()),
shapeGroup.isHidden(), contentsFromModels(lottieDrawable, composition, layer, shapeGroup.getItems()),
findTransform(shapeGroup.getItems()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.collection.LongSparseArray;

import com.airbnb.lottie.L;
import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.LottieProperty;
import com.airbnb.lottie.animation.LPaint;
Expand Down Expand Up @@ -64,14 +65,14 @@ public class GradientFillContent
float blurMaskFilterRadius = 0f;
@Nullable private DropShadowKeyframeAnimation dropShadowAnimation;

public GradientFillContent(final LottieDrawable lottieDrawable, BaseLayer layer, GradientFill fill) {
public GradientFillContent(final LottieDrawable lottieDrawable, LottieComposition composition, BaseLayer layer, GradientFill fill) {
this.layer = layer;
name = fill.getName();
hidden = fill.isHidden();
this.lottieDrawable = lottieDrawable;
type = fill.getGradientType();
path.setFillType(fill.getFillType());
cacheSteps = (int) (lottieDrawable.getComposition().getDuration() / CACHE_STEPS_MS);
cacheSteps = (int) (composition.getDuration() / CACHE_STEPS_MS);

colorAnimation = fill.getGradientColor().createAnimation();
colorAnimation.addUpdateListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.ModifierContent;
Expand Down Expand Up @@ -104,7 +105,7 @@ public TransformKeyframeAnimation createAnimation() {

@Nullable
@Override
public Content toContent(LottieDrawable drawable, BaseLayer layer) {
public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.PointF;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.EllipseContent;
Expand All @@ -25,7 +26,7 @@ public CircleShape(String name, AnimatableValue<PointF, PointF> position,
this.hidden = hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new EllipseContent(drawable, layer, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.model.layer.BaseLayer;

public interface ContentModel {
@Nullable Content toContent(LottieDrawable drawable, BaseLayer layer);
@Nullable Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.GradientFillContent;
Expand Down Expand Up @@ -75,8 +76,8 @@ public boolean isHidden() {
return hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
return new GradientFillContent(drawable, layer, this);
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new GradientFillContent(drawable, composition, layer, this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.GradientStrokeContent;
Expand Down Expand Up @@ -103,7 +104,7 @@ public boolean isHidden() {
return hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new GradientStrokeContent(drawable, layer, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.MergePathsContent;
Expand Down Expand Up @@ -58,7 +59,7 @@ public boolean isHidden() {
return hidden;
}

@Override @Nullable public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override @Nullable public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
if (!drawable.enableMergePathsForKitKatAndAbove()) {
Logger.warning("Animation contains merge paths but they are disabled.");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.PointF;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.PolystarContent;
Expand Down Expand Up @@ -104,7 +105,7 @@ public boolean isReversed() {
return isReversed;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new PolystarContent(drawable, layer, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.PointF;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.RectangleContent;
Expand Down Expand Up @@ -45,7 +46,7 @@ public boolean isHidden() {
return hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new RectangleContent(drawable, layer, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.RepeaterContent;
Expand Down Expand Up @@ -45,7 +46,7 @@ public boolean isHidden() {
return hidden;
}

@Nullable @Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Nullable @Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new RepeaterContent(drawable, layer, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.RoundedCornersContent;
Expand All @@ -25,7 +26,7 @@ public AnimatableValue<Float, Float> getCornerRadius() {
return cornerRadius;
}

@Nullable @Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Nullable @Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new RoundedCornersContent(drawable, layer, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.FillContent;
Expand Down Expand Up @@ -49,7 +50,7 @@ public boolean isHidden() {
return hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new FillContent(drawable, layer, this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.airbnb.lottie.model.content;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.ContentGroup;
Expand Down Expand Up @@ -31,8 +32,8 @@ public boolean isHidden() {
return hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
return new ContentGroup(drawable, layer, this);
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new ContentGroup(drawable, layer, this, composition);
}

@Override public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.airbnb.lottie.model.content;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.ShapeContent;
Expand Down Expand Up @@ -27,7 +28,7 @@ public AnimatableShapeValue getShapePath() {
return shapePath;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new ShapeContent(drawable, layer, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.StrokeContent;
Expand Down Expand Up @@ -78,7 +79,7 @@ public ShapeStroke(String name, @Nullable AnimatableFloatValue offset,
this.hidden = hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new StrokeContent(drawable, layer, this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.airbnb.lottie.model.content;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.TrimPathContent;
Expand Down Expand Up @@ -65,7 +66,7 @@ public boolean isHidden() {
return hidden;
}

@Override public Content toContent(LottieDrawable drawable, BaseLayer layer) {
@Override public Content toContent(LottieDrawable drawable, LottieComposition composition, BaseLayer layer) {
return new TrimPathContent(layer, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static BaseLayer forModel(
CompositionLayer compositionLayer, Layer layerModel, LottieDrawable drawable, LottieComposition composition) {
switch (layerModel.getLayerType()) {
case SHAPE:
return new ShapeLayer(drawable, layerModel, compositionLayer);
return new ShapeLayer(drawable, layerModel, compositionLayer, composition);
case PRE_COMP:
return new CompositionLayer(drawable, layerModel,
composition.getPrecomps(layerModel.getRefId()), composition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.animation.content.Content;
import com.airbnb.lottie.animation.content.ContentGroup;
Expand All @@ -22,13 +23,13 @@ public class ShapeLayer extends BaseLayer {
private final ContentGroup contentGroup;
private final CompositionLayer compositionLayer;

ShapeLayer(LottieDrawable lottieDrawable, Layer layerModel, CompositionLayer compositionLayer) {
ShapeLayer(LottieDrawable lottieDrawable, Layer layerModel, CompositionLayer compositionLayer, LottieComposition composition) {
super(lottieDrawable, layerModel);
this.compositionLayer = compositionLayer;

// Naming this __container allows it to be ignored in KeyPath matching.
ShapeGroup shapeGroup = new ShapeGroup("__container", layerModel.getShapes(), false);
contentGroup = new ContentGroup(lottieDrawable, this, shapeGroup);
contentGroup = new ContentGroup(lottieDrawable, this, shapeGroup, composition);
contentGroup.setContents(Collections.<Content>emptyList(), Collections.<Content>emptyList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private List<ContentGroup> getContentsForCharacter(FontCharacter character) {
List<ContentGroup> contents = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ShapeGroup sg = shapes.get(i);
contents.add(new ContentGroup(lottieDrawable, this, sg));
contents.add(new ContentGroup(lottieDrawable, this, sg, composition));
}
contentsForCharacter.put(character, contents);
return contents;
Expand Down