Skip to content

Commit

Permalink
LottieComposition: Add getHeight & getWidth function to return origin…
Browse files Browse the repository at this point in the history
…al dimensions.
  • Loading branch information
vanniktech committed Jun 28, 2024
1 parent 99b0683 commit a08adc3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class LottieClipSpecTest {
SparseArrayCompat(),
emptyMap(),
markers,
0,
0,
)
return composition
}
Expand Down
14 changes: 13 additions & 1 deletion lottie/src/main/java/com/airbnb/lottie/LottieComposition.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ public class LottieComposition {
*/
private int maskAndMatteCount = 0;

private int width;
private int height;

@RestrictTo(RestrictTo.Scope.LIBRARY)
public void init(Rect bounds, float startFrame, float endFrame, float frameRate,
List<Layer> layers, LongSparseArray<Layer> layerMap, Map<String,
List<Layer>> precomps, Map<String, LottieImageAsset> images, float imagesDpScale,
SparseArrayCompat<FontCharacter> characters, Map<String, Font> fonts,
List<Marker> markers) {
List<Marker> markers, int width, int height) {
this.bounds = bounds;
this.startFrame = startFrame;
this.endFrame = endFrame;
Expand All @@ -90,6 +93,8 @@ public void init(Rect bounds, float startFrame, float endFrame, float frameRate,
this.characters = characters;
this.fonts = fonts;
this.markers = markers;
this.width = width;
this.height = height;
}

@RestrictTo(RestrictTo.Scope.LIBRARY)
Expand Down Expand Up @@ -233,6 +238,13 @@ public float getDurationFrames() {
return endFrame - startFrame;
}

public int getHeight() {
return height;
}

public int getWidth() {
return width;
}

@NonNull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static LottieComposition parse(JsonReader reader) throws IOException {
Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight);

composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps,
images, Utils.dpScale(), characters, fonts, markers);
images, Utils.dpScale(), characters, fonts, markers, width, height);

return composition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import android.graphics.Rect;
import androidx.collection.LongSparseArray;
import androidx.collection.SparseArrayCompat;
import com.airbnb.lottie.model.Font;
import com.airbnb.lottie.model.FontCharacter;
import com.airbnb.lottie.model.Marker;
import com.airbnb.lottie.model.layer.Layer;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -16,7 +12,6 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static junit.framework.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -39,7 +34,7 @@ private LottieComposition createComposition(int startFrame, int endFrame) {
composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<>(),
new LongSparseArray<>(0), new HashMap<>(0),
new HashMap<>(0), 1f, new SparseArrayCompat<>(0),
new HashMap<>(0), new ArrayList<>());
new HashMap<>(0), new ArrayList<>(), 0, 0);
return composition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import android.graphics.Rect;
import androidx.collection.LongSparseArray;
import androidx.collection.SparseArrayCompat;
import com.airbnb.lottie.model.Font;
import com.airbnb.lottie.model.FontCharacter;
import com.airbnb.lottie.model.Marker;
import com.airbnb.lottie.model.layer.Layer;
import com.airbnb.lottie.utils.LottieValueAnimator;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -17,7 +13,6 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import static junit.framework.Assert.assertEquals;
Expand Down Expand Up @@ -63,7 +58,7 @@ private LottieComposition createComposition(int startFrame, int endFrame) {
composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<>(),
new LongSparseArray<>(0), new HashMap<>(0),
new HashMap<>(0), 1f, new SparseArrayCompat<>(0),
new HashMap<>(0), new ArrayList<>());
new HashMap<>(0), new ArrayList<>(), 0, 0);
return composition;
}

Expand Down

0 comments on commit a08adc3

Please sign in to comment.