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

Factor composition start and end frames (work area) into progress calculation #366

Merged
merged 2 commits into from
Jul 3, 2017
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
Binary file modified LottieSample/screenshots/9squares-AlBoardman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/LottieLogo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/LottieLogo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/PinJump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/Tests_ShapeTypes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/lottiefiles.com_-_ATM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/lottiefiles.com_-_Loading_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/lottiefiles.com_-_Permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/lottiefiles.com_-_Play_and_Like_It.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/lottiefiles.com_-_Star_Wars_Rey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/same_composition_first_run_PinJump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/same_composition_second_run_PinJump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LottieSample/screenshots/test_changing_compositions_PinJump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,4 @@ private static void throwMissingTransform(String missingProperty) {
throw new IllegalArgumentException("Missing transform for " + missingProperty);
}
}

}
23 changes: 18 additions & 5 deletions lottie/src/main/java/com/airbnb/lottie/Keyframe.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ static void setEndFrames(List<? extends Keyframe<?>> keyframes) {
@SuppressWarnings("WeakerAccess") final float startFrame;
@SuppressWarnings("WeakerAccess") @Nullable Float endFrame;

private float startProgress = Float.MIN_VALUE;
private float endProgress = Float.MIN_VALUE;

public Keyframe(LottieComposition composition, @Nullable T startValue, @Nullable T endValue,
@Nullable Interpolator interpolator, float startFrame, @Nullable Float endFrame) {
this.composition = composition;
Expand All @@ -60,15 +63,25 @@ public Keyframe(LottieComposition composition, @Nullable T startValue, @Nullable
this.endFrame = endFrame;
}

@FloatRange(from = 0f, to = 1f)
float getStartProgress() {
return startFrame / composition.getDurationFrames();
if (startProgress == Float.MIN_VALUE) {
startProgress = (startFrame - composition.getStartFrame()) / composition.getDurationFrames();
}
return startProgress;
}

@FloatRange(from = 0f, to = 1f)
float getEndProgress() {
//noinspection Range
return endFrame == null ? 1f : endFrame / composition.getDurationFrames();
if (endProgress == Float.MIN_VALUE) {
if (endFrame == null) {
endProgress = 1f;
} else {
float startProgress = getStartProgress();
float durationFrames = endFrame - startFrame;
float durationProgress = durationFrames / composition.getDurationFrames();
endProgress = startProgress + durationProgress;
}
}
return endProgress;
}

boolean isStatic() {
Expand Down
8 changes: 6 additions & 2 deletions lottie/src/main/java/com/airbnb/lottie/LottieComposition.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Layer layerModelForId(long id) {

@SuppressWarnings("WeakerAccess") public long getDuration() {
long frameDuration = endFrame - startFrame;
return (long) (frameDuration / (float) frameRate * 1000);
return (long) (frameDuration / frameRate * 1000);
}

int getMajorVersion() {
Expand All @@ -109,6 +109,10 @@ int getPatchVersion() {
return patchVersion;
}

long getStartFrame() {
return startFrame;
}

long getEndFrame() {
return endFrame;
}
Expand Down Expand Up @@ -139,7 +143,7 @@ Map<String, LottieImageAsset> getImages() {
}

float getDurationFrames() {
return getDuration() * (float) frameRate / 1000f;
return getDuration() * frameRate / 1000f;
}


Expand Down