Skip to content

Commit

Permalink
Added radius, size & position value callbacks for rectangle (airbnb#1146
Browse files Browse the repository at this point in the history
)

Fixes airbnb#894
  • Loading branch information
digitalbuddha authored and gpeal committed Mar 10, 2019
1 parent be65104 commit 77ebba9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
43 changes: 23 additions & 20 deletions LottieSample/src/androidTest/java/com/airbnb/lottie/LottieTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package com.airbnb.lottie

import android.Manifest
import android.content.res.Resources
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.PointF
import android.graphics.PorterDuff
import android.graphics.*
import android.util.DisplayMetrics
import android.util.Log
import android.view.View
Expand All @@ -24,26 +19,14 @@ import com.airbnb.lottie.model.LottieCompositionCache
import com.airbnb.lottie.samples.BuildConfig
import com.airbnb.lottie.samples.SnapshotTestActivity
import com.airbnb.lottie.samples.views.FilmStripView
import com.airbnb.lottie.value.LottieInterpolatedIntegerValue
import com.airbnb.lottie.value.LottieRelativeFloatValueCallback
import com.airbnb.lottie.value.LottieRelativePointValueCallback
import com.airbnb.lottie.value.LottieValueCallback
import com.airbnb.lottie.value.ScaleXY
import com.airbnb.lottie.value.*
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.S3ObjectSummary
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -411,12 +394,32 @@ class LottieTest {
LottieProperty.TRANSFORM_SCALE,
LottieValueCallback(ScaleXY(0.5f, 0.5f)))

testDynamicProperty(
"Rectangle corner roundedness",
KeyPath("Shape Layer 1", "Rectangle", "Rectangle Path 1"),
LottieProperty.CORNER_RADIUS,
LottieValueCallback(7f))

testDynamicProperty(
"Rectangle position",
KeyPath("Shape Layer 1", "Rectangle", "Rectangle Path 1"),
LottieProperty.POSITION,
LottieRelativePointValueCallback(PointF(20f, 20f)))

testDynamicProperty(
"Rectangle size",
KeyPath("Shape Layer 1", "Rectangle", "Rectangle Path 1"),
LottieProperty.RECTANGLE_SIZE,
LottieRelativePointValueCallback(PointF(30f, 40f)))

testDynamicProperty(
"Ellipse position",
KeyPath("Shape Layer 1", "Ellipse", "Ellipse Path 1"),
LottieProperty.POSITION,
LottieRelativePointValueCallback(PointF(20f, 20f)))



testDynamicProperty(
"Ellipse size",
KeyPath("Shape Layer 1", "Ellipse", "Ellipse Path 1"),
Expand Down
7 changes: 4 additions & 3 deletions lottie/src/main/java/com/airbnb/lottie/LottieProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ public interface LottieProperty {
Integer TRANSFORM_OPACITY = 3;
/** [0,100] */
Integer OPACITY = 4;

/** In Px */
PointF TRANSFORM_ANCHOR_POINT = new PointF();
/** In Px */
PointF TRANSFORM_POSITION = new PointF();
/** In Px */
PointF ELLIPSE_SIZE = new PointF();
/** In Px */
PointF RECTANGLE_SIZE = new PointF();
/** In degrees */
Float CORNER_RADIUS = 0f;
/** In Px */
PointF POSITION = new PointF();

ScaleXY TRANSFORM_SCALE = new ScaleXY();

/** In degrees */
Float TRANSFORM_ROTATION = 1f;
/** 0-85 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.annotation.Nullable;

import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.LottieProperty;
import com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation;
import com.airbnb.lottie.animation.keyframe.FloatKeyframeAnimation;
import com.airbnb.lottie.model.KeyPath;
Expand Down Expand Up @@ -153,8 +154,13 @@ private void invalidate() {
MiscUtils.resolveKeyPath(keyPath, depth, accumulator, currentPartialKeyPath, this);
}

@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {

@Override public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
if (property == LottieProperty.RECTANGLE_SIZE) {
sizeAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
} else if (property == LottieProperty.POSITION) {
positionAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
} else if (property == LottieProperty.CORNER_RADIUS) {
cornerRadiusAnimation.setValueCallback((LottieValueCallback<Float>) callback);
}
}
}

0 comments on commit 77ebba9

Please sign in to comment.