android supports animation
This commit is contained in:
parent
410ad72d71
commit
4e596642f2
@ -16,8 +16,11 @@
|
|||||||
package pub.doric.shader;
|
package pub.doric.shader;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@ -169,7 +172,17 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "bgColor":
|
case "bgColor":
|
||||||
view.setBackgroundColor(prop.asNumber().toInt());
|
if (isAnimating()) {
|
||||||
|
ObjectAnimator animator = ObjectAnimator.ofInt(
|
||||||
|
this,
|
||||||
|
name,
|
||||||
|
getBgColor(),
|
||||||
|
prop.asNumber().toInt());
|
||||||
|
animator.setEvaluator(new ArgbEvaluator());
|
||||||
|
addAnimator(animator);
|
||||||
|
} else {
|
||||||
|
setBgColor(prop.asNumber().toInt());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "onClick":
|
case "onClick":
|
||||||
final String functionId = prop.asString().value();
|
final String functionId = prop.asString().value();
|
||||||
@ -425,4 +438,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DoricMethod
|
||||||
|
public int getBgColor() {
|
||||||
|
if (mView.getBackground() instanceof ColorDrawable) {
|
||||||
|
return ((ColorDrawable) mView.getBackground()).getColor();
|
||||||
|
}
|
||||||
|
return Color.TRANSPARENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DoricMethod
|
||||||
|
public void setBgColor(int color) {
|
||||||
|
mView.setBackgroundColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,30 @@
|
|||||||
import { animate, Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, IVLayout, modal, IText, network, View, stack } from "doric";
|
import { animate, Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, IVLayout, modal, IText, network, View, stack, IHLayout, hlayout, IView, text } from "doric";
|
||||||
import { title, label, colors, box } from "./utils";
|
import { title, colors, box } from "./utils";
|
||||||
|
|
||||||
@Entry
|
function thisLabel(str: string) {
|
||||||
class AnimatorDemo extends Panel {
|
return text({
|
||||||
build(rootView: Group): void {
|
text: str,
|
||||||
const view = box(2)
|
|
||||||
vlayout([
|
|
||||||
title("Animator Demo"),
|
|
||||||
label('Reset').apply({
|
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 50,
|
height: 50,
|
||||||
bgColor: colors[4],
|
bgColor: colors[4],
|
||||||
textSize: 20,
|
textSize: 20,
|
||||||
textColor: Color.WHITE,
|
textColor: Color.WHITE,
|
||||||
layoutConfig: layoutConfig().exactly(),
|
layoutConfig: layoutConfig().exactly(),
|
||||||
} as IText).also(v => {
|
})
|
||||||
v.onClick = () => {
|
}
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
class AnimatorDemo extends Panel {
|
||||||
|
build(rootView: Group): void {
|
||||||
|
const view = box(2)
|
||||||
|
let idx = 0
|
||||||
|
vlayout([
|
||||||
|
title("Animator Demo"),
|
||||||
|
vlayout(
|
||||||
|
[
|
||||||
|
hlayout([
|
||||||
|
thisLabel('Reset').apply({
|
||||||
|
onClick: () => {
|
||||||
animate(this)({
|
animate(this)({
|
||||||
animations: () => {
|
animations: () => {
|
||||||
view.width = view.height = 20
|
view.width = view.height = 20
|
||||||
@ -23,53 +32,48 @@ class AnimatorDemo extends Panel {
|
|||||||
duration: 3000,
|
duration: 3000,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
modal(context).toast('Fininshed')
|
modal(context).toast('Fininshed')
|
||||||
}, (e: any) => {
|
}).catch(e => {
|
||||||
modal(context).toast(`${e}`)
|
modal(context).toast(`${e}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
label('Width').apply({
|
]),
|
||||||
width: 100,
|
hlayout([
|
||||||
height: 50,
|
thisLabel('Width').apply({
|
||||||
bgColor: colors[0],
|
onClick: () => {
|
||||||
textSize: 20,
|
|
||||||
textColor: Color.WHITE,
|
|
||||||
layoutConfig: layoutConfig().exactly(),
|
|
||||||
} as IText).also(v => {
|
|
||||||
v.onClick = () => {
|
|
||||||
animate(this)({
|
animate(this)({
|
||||||
animations: () => {
|
animations: () => {
|
||||||
view.width = 300
|
view.width = 200
|
||||||
},
|
},
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
}).then(() => {
|
|
||||||
modal(context).toast('Fininshed')
|
|
||||||
}, (e: any) => {
|
|
||||||
modal(context).toast(`${e}`)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
label('Height').apply({
|
thisLabel('Height').apply({
|
||||||
width: 100,
|
onClick: () => {
|
||||||
height: 50,
|
|
||||||
bgColor: colors[0],
|
|
||||||
textSize: 20,
|
|
||||||
textColor: Color.WHITE,
|
|
||||||
layoutConfig: layoutConfig().exactly(),
|
|
||||||
} as IText).also(v => {
|
|
||||||
v.onClick = () => {
|
|
||||||
animate(this)({
|
animate(this)({
|
||||||
animations: () => {
|
animations: () => {
|
||||||
view.height = 300
|
view.height = 200
|
||||||
},
|
},
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
}).then(() => {
|
|
||||||
modal(context).toast('Fininshed')
|
|
||||||
}, (e: any) => {
|
|
||||||
modal(context).toast(`${e}`)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
]).apply({ space: 10 } as IHLayout),
|
||||||
|
hlayout([
|
||||||
|
thisLabel('BgColor').apply({
|
||||||
|
onClick: () => {
|
||||||
|
animate(this)({
|
||||||
|
animations: () => {
|
||||||
|
view.bgColor = colors[(idx++) % colors.length]
|
||||||
|
},
|
||||||
|
duration: 3000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
]).apply({ space: 10 } as IHLayout),
|
||||||
|
]
|
||||||
|
).apply({ space: 10 } as IVLayout),
|
||||||
stack([
|
stack([
|
||||||
view.also(v => {
|
view.also(v => {
|
||||||
v.left = 20
|
v.left = 20
|
||||||
|
@ -17,7 +17,11 @@ function fromDir(startPath, filter) {
|
|||||||
fromDir(filename, filter);
|
fromDir(filename, filter);
|
||||||
}
|
}
|
||||||
else if (filename.indexOf(filter) >= 0) {
|
else if (filename.indexOf(filter) >= 0) {
|
||||||
|
try {
|
||||||
doMerge(startPath, files[i])
|
doMerge(startPath, files[i])
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user