Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WEEX-216][android] WXAnimation Fix Memory Leak and performance improve #1026

Merged
merged 2 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private static void register() {

registerModule("modal", WXModalUIModule.class, false);
registerModule("instanceWrap", WXInstanceWrap.class, true);
registerModule("animation", WXAnimationModule.class, true);
registerModule("animation", WXAnimationModule.class, false);
registerModule("webview", WXWebViewModule.class, true);
registerModule("navigator", WXNavigatorModule.class);
registerModule("stream", WXStreamModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static DOMAction getRemoveEvent(String ref, String event) {
}


public static DOMAction getAnimationAction(@NonNull final String ref, @NonNull String animation,
public static DOMAction getAnimationAction(@NonNull final String ref, @NonNull JSONObject animation,
@Nullable final String callBack){
return new AnimationAction(ref, animation, callBack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AnimationAction implements DOMAction, RenderAction {

@Nullable
private
final String animation;
final JSONObject animation;

@Nullable
private
Expand All @@ -89,7 +89,7 @@ class AnimationAction implements DOMAction, RenderAction {
private
WXAnimationBean mAnimationBean;

AnimationAction(@NonNull final String ref, @Nullable String animation,
AnimationAction(@NonNull final String ref, @Nullable JSONObject animation,
@Nullable final String callBack) {
this.ref = ref;
this.animation = animation;
Expand All @@ -113,9 +113,9 @@ public void executeDom(DOMActionContext context) {
try {
WXDomObject domObject;
if (!context.isDestory() &&
!TextUtils.isEmpty(animation) &&
animation != null &&
(domObject = context.getDomByRef(ref)) != null) {
WXAnimationBean animationBean = JSONObject.parseObject(animation, WXAnimationBean.class);
WXAnimationBean animationBean = JSONObject.toJavaObject(animation, WXAnimationBean.class);
if (animationBean != null && animationBean.styles != null) {
int width = (int) domObject.getLayoutWidth();
int height = (int) domObject.getLayoutHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.annotation.JSMethod;
Expand All @@ -31,13 +32,14 @@
import com.taobao.weex.dom.action.Actions;
import com.taobao.weex.ui.component.WXComponent;


import static com.taobao.weex.dom.action.Actions.getAnimationAction;

public class WXAnimationModule extends WXModule {

@JSMethod
public void transition(@Nullable String ref, @Nullable String animation, @Nullable String callBack) {
if (!TextUtils.isEmpty(ref) && !TextUtils.isEmpty(animation) && mWXSDKInstance != null) {
public void transition(@Nullable String ref, @Nullable JSONObject animation, @Nullable String callBack) {
if (!TextUtils.isEmpty(ref) && animation != null && mWXSDKInstance != null) {
DOMAction animationActions = getAnimationAction(ref, animation, callBack);
//Due to animation module rely on the result of the css-layout and the batch mechanism of
//css-layout, the animation.transition must be delayed the batch time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
public class WXReflectionUtils {

public static Object parseArgument(Type paramClazz, Object value) {
if(value != null){
if(value.getClass() == paramClazz){
return value;
}
if(paramClazz instanceof Class){
if( ((Class<?>) paramClazz).isAssignableFrom(value.getClass())) {
return value;
}
}
}
if (paramClazz == String.class) {
return value instanceof String ? value : JSON.toJSONString(value);
} else if (paramClazz == int.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.ui.animation;

import com.alibaba.fastjson.JSONObject;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;

Expand Down Expand Up @@ -50,8 +51,8 @@ public void setUp() throws Exception {

@Test
public void testTransition() throws Exception {
module.transition("","","");
module.transition("test","test","");
module.transition("", JSONObject.parseObject("{}"),"");
module.transition("test", JSONObject.parseObject("{\"test\":\"test\"}"),"");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ static class TestA{

@Test
public void testParseArgument() throws Exception {


Object value = WXReflectionUtils.parseArgument(String.class,"dkdkdkdk");
assertTrue(value instanceof String);

value = WXReflectionUtils.parseArgument(int.class,123444);
assertTrue(value instanceof Integer);

value = WXReflectionUtils.parseArgument(long.class,"123444");
assertTrue(value instanceof Long);

Expand All @@ -70,6 +75,10 @@ public void testParseArgument() throws Exception {
JSONObject j = new JSONObject();
j.put("a","b");
j.put("c",23);

value = WXReflectionUtils.parseArgument(Map.class,j);
assertTrue(value == j);

value = WXReflectionUtils.parseArgument(String.class,j);
assertTrue(value instanceof String);

Expand Down