Skip to content

Commit

Permalink
fixed string check
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Jul 24, 2017
1 parent ef5ed6b commit 8100a44
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 14 deletions.
1 change: 1 addition & 0 deletions android/platform/android/res/layout/layout_lottie.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
android:scaleType="centerInside"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
/>
</LinearLayout>
52 changes: 38 additions & 14 deletions android/src/ti/animation/LottieViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class LottieViewProxy extends TiViewProxy
private int width = 0;
private int height = 0;
private boolean useSoftwareRendering = false;
private boolean mergePath = false;
private ScaleType viewScaleMode = ScaleType.CENTER_INSIDE;

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

Expand Down Expand Up @@ -119,8 +121,7 @@ private void animationEvent(float percentage, int status){
}
}

private class LottieView extends TiUIView
{
private class LottieView extends TiUIView {
public LottieView(TiViewProxy proxy) {
super(proxy);

Expand All @@ -143,24 +144,39 @@ public LottieView(TiViewProxy proxy) {
appContext = TiApplication.getInstance();
isReady = true;

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

lottieView.enableMergePathsForKitKatAndAbove(mergePath);

if (loadFile != ""){
setFile(loadFile);
}
}

@Override
public void processProperties(KrollDict d)
{
public void processProperties(KrollDict d) {
super.processProperties(d);
if (d.containsKey("scaleMode")) {
String scaleMode = d.getString("scaleMode");
if (scaleMode.equals("center")) {
viewScaleMode = ScaleType.CENTER;
} else if (scaleMode.equals("centerCrop")) {
viewScaleMode = ScaleType.CENTER_CROP;
} else if (scaleMode.equals("centerInside")) {
viewScaleMode = ScaleType.CENTER_INSIDE;
} else {
viewScaleMode = ScaleType.CENTER_INSIDE;
}
if (isReady){
lottieView.setScaleType(viewScaleMode);
}
}
}
}

Expand Down Expand Up @@ -215,6 +231,12 @@ public void handleCreationDict(KrollDict options)
if (options.containsKey("update")) {
callbackUpdate =(KrollFunction) options.get("update");
}
if (options.containsKey("mergePath")) {
mergePath = options.getBoolean("mergePath");
if (isReady){
lottieView.enableMergePathsForKitKatAndAbove(mergePath);
}
}
if (options.containsKey("disableHardwareAcceleration")){
if (options.getBoolean("disableHardwareAcceleration")){
if (isReady){
Expand All @@ -226,16 +248,18 @@ public void handleCreationDict(KrollDict options)
}
if (options.containsKey("scaleMode")) {
String scaleMode = options.getString("scaleMode");
if (scaleMode == "center") {
lottieView.setScaleType(ScaleType.CENTER);
} else if (scaleMode == "centerCrop") {
lottieView.setScaleType(ScaleType.CENTER_CROP);
} else if (scaleMode == "centerInside") {
lottieView.setScaleType(ScaleType.CENTER_INSIDE);
} else if (scaleMode == "fitXY") {
lottieView.setScaleType(ScaleType.FIT_XY);
if (scaleMode.equals("center")) {
viewScaleMode = ScaleType.CENTER;
} else if (scaleMode.equals("centerCrop")) {
viewScaleMode = ScaleType.CENTER_CROP;
} else if (scaleMode.equals("centerInside")) {
viewScaleMode = ScaleType.CENTER_INSIDE;
} else {
viewScaleMode = ScaleType.CENTER_INSIDE;
}
if (isReady){
lottieView.setScaleType(viewScaleMode);
}

}
}

Expand Down
75 changes: 75 additions & 0 deletions example/scaleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var TiAnimation = require('ti.animation');
var isAndroid = (Ti.Platform.osname == 'android');

var win = Ti.UI.createWindow({
backgroundColor: '#fff',
title: '',
fullscreen: true
});

var scroller = Ti.UI.createScrollView({
width: Ti.UI.FILL,
height: Ti.UI.FILL,
layout: "vertical"
})

var ani1 = TiAnimation.createLottieView({
file: 'sample_lottie.json',
top: 5,
loop: true,
width: 200,
height: 200,
borderWidth: 1,
borderColor: "#000",
autoStart: true
});
var ani2 = TiAnimation.createLottieView({
file: 'sample_lottie.json',
top: 5,
loop: true,
width: 20,
height: 20,
borderWidth: 1,
borderColor: "#000",
autoStart: true
});
var ani3 = TiAnimation.createLottieView({
file: 'sample_lottie.json',
top: 5,
loop: true,
width: 200,
height: 20,
borderWidth: 1,
borderColor: "#000",
autoStart: true
});
var ani4 = TiAnimation.createLottieView({
file: 'sample_lottie.json',
top: 5,
loop: true,
width: 320,
height: 50,
borderWidth: 1,
borderColor: "#000",
autoStart: true,
scaleMode: "centerCrop"
});
var ani5 = TiAnimation.createLottieView({
file: 'sample_lottie.json',
top: 5,
loop: true,
width: 320,
height: 50,
borderWidth: 1,
borderColor: "#000",
autoStart: true
});

scroller.add(ani1);
scroller.add(ani2);
scroller.add(ani3);
scroller.add(ani4);
scroller.add(ani5);
win.add(scroller);

win.open();

0 comments on commit 8100a44

Please sign in to comment.