Skip to content

Commit

Permalink
Take composition start and end frame into account (work area)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Peal committed Jul 3, 2017
1 parent f95b9d4 commit e2022e8
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 7 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 @@ -157,4 +157,7 @@ private static void throwMissingTransform(String missingProperty) {
}
}

@Override public String toString() {
return super.toString();
}
}
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
1 change: 1 addition & 0 deletions lottie/src/main/java/com/airbnb/lottie/Layer.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ String toString(String prefix) {
sb.append(prefix).append("\t\t").append(shape).append("\n");
}
}

return sb.toString();
}

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 e2022e8

Please sign in to comment.