Skip to content

Commit

Permalink
complete callback, allow scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Mar 16, 2017
1 parent 4b77fb3 commit 0548b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion android/platform/android/res/layout/layout_lottie.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<LinearLayout android:background="#00ffffff" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<com.airbnb.lottie.LottieAnimationView android:id="@+id/animation_view" android:layout_gravity="center" android:scaleType="center" android:layout_width="match_parent" android:layout_height="match_parent"/>
<com.airbnb.lottie.LottieAnimationView android:id="@+id/animation_view" android:layout_gravity="center" android:scaleType="centerCrop" android:layout_width="match_parent" android:layout_height="match_parent"/>
</LinearLayout>
23 changes: 21 additions & 2 deletions android/src/ti/animation/LottieViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class LottieViewProxy extends TiViewProxy
private TiApplication appContext;
private KrollFunction callbackUpdate = null;
private KrollFunction callbackComplete = null;
private KrollFunction callbackReady = null;
private Resources resources;
private String loadFile = "";
private String assetFolder = "";
Expand All @@ -63,6 +64,8 @@ public class LottieViewProxy extends TiViewProxy
private JSONObject jsonObject;
private int width = 0;
private int height = 0;
private boolean useSoftwareRendering = false;

protected static final int MSG_STARTANIMATION = KrollProxy.MSG_LAST_ID + 101;

@Kroll.constant public static final int ANIMATION_START = 1;
Expand Down Expand Up @@ -141,7 +144,12 @@ public LottieView(TiViewProxy proxy) {

lottieView.addAnimatorUpdateListener(new AnimatorUpdateListener());
lottieView.addAnimatorListener(new AnimatorListener());
lottieView.setLayerType(View.LAYER_TYPE_HARDWARE,null);
if (useSoftwareRendering){
lottieView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
} else {
lottieView.setLayerType(View.LAYER_TYPE_HARDWARE,null);
}


if (loadFile != ""){
setFile(loadFile);
Expand Down Expand Up @@ -208,7 +216,11 @@ public void handleCreationDict(KrollDict options)
}
if (options.containsKey("disableHardwareAcceleration")){
if (options.getBoolean("disableHardwareAcceleration")){
lottieView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
if (isReady){
lottieView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
} else {
useSoftwareRendering = true;
}
}
}
}
Expand Down Expand Up @@ -315,6 +327,8 @@ public void addEventListener(String evt, KrollFunction kf) {
callbackUpdate =(KrollFunction) kf;
} else if (evt.equals("complete")) {
callbackComplete =(KrollFunction) kf;
} else if (evt.equals("ready")) {
callbackReady =(KrollFunction) kf;
}
}

Expand Down Expand Up @@ -370,6 +384,11 @@ public void onCompositionLoaded(LottieComposition composition) {
if (isAutoStart){
lottieView.playAnimation();
}

if (callbackReady != null) {
HashMap<String,Object> event = new HashMap<String, Object>();
callbackReady.call(getKrollObject(), event);
}
}
});
}
Expand Down

0 comments on commit 0548b06

Please sign in to comment.