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

LottieComposition: Add getUnscaledHeight & getUnscaledWidth functions. #2514

Merged
merged 1 commit into from
Aug 1, 2024
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
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 unscaledWidth;
private int unscaledHeight;

@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 unscaledWidth, int unscaledHeight) {
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.unscaledWidth = unscaledWidth;
this.unscaledHeight = unscaledHeight;
}

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

public int getUnscaledWidth() {
return unscaledWidth;
}

public int getUnscaledHeight() {
return unscaledHeight;
}

@NonNull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static LottieComposition parse(JsonReader reader) throws IOException {
float frameRate = 0f;
final LongSparseArray<Layer> layerMap = new LongSparseArray<>();
final List<Layer> layers = new ArrayList<>();
int width = 0;
int height = 0;
int unscaledWidth = 0;
int unscaledHeight = 0;
Map<String, List<Layer>> precomps = new HashMap<>();
Map<String, LottieImageAsset> images = new HashMap<>();
Map<String, Font> fonts = new HashMap<>();
Expand All @@ -57,10 +57,10 @@ public static LottieComposition parse(JsonReader reader) throws IOException {
while (reader.hasNext()) {
switch (reader.selectName(NAMES)) {
case 0:
width = reader.nextInt();
unscaledWidth = reader.nextInt();
break;
case 1:
height = reader.nextInt();
unscaledHeight = reader.nextInt();
break;
case 2:
startFrame = (float) reader.nextDouble();
Expand Down Expand Up @@ -102,12 +102,12 @@ public static LottieComposition parse(JsonReader reader) throws IOException {
reader.skipValue();
}
}
int scaledWidth = (int) (width * scale);
int scaledHeight = (int) (height * scale);
int scaledWidth = (int) (unscaledWidth * scale);
int scaledHeight = (int) (unscaledHeight * scale);
Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight);

composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps,
images, Utils.dpScale(), characters, fonts, markers);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I do pass the unscaled width & height here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make the names very clearly named unscaledWidth and unscaledHeight?

images, Utils.dpScale(), characters, fonts, markers, unscaledWidth, unscaledHeight);

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
Loading