Skip to content

Commit

Permalink
Factor composition start and end frames (work area) into progress cal…
Browse files Browse the repository at this point in the history
…culation (#366)

#257
  • Loading branch information
gpeal authored Jul 3, 2017
1 parent f95b9d4 commit 018e849
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 8 deletions.
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

0 comments on commit 018e849

Please sign in to comment.