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

Commit

Permalink
* [Android] Support rotateX and rotateY, optimize animation as well.
Browse files Browse the repository at this point in the history
@notdanger

* [Use LayoutParamsProperty instead of DimensionUpdateListener to achieve height/width animation.](http://dotwe.org/vue/c7a70462a136b61e11ab37f384862003)
* [Support rotateX and rotateY.](http://dotwe.org/vue/e712dd2ad4df470bab940d8e0e6d052d).
* Stop remove transform and transform-origin from WXStyle in UpdateStyleAction.
* Stop execute animation callback if corresponding WXInstance is destroyed when animation finished.

Corresponding [JIRA issue](https://issues.apache.org/jira/browse/WEEX-38).
  • Loading branch information
YorkShen committed Jun 8, 2017
1 parent bd00ba8 commit cd91163
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
Expand All @@ -48,17 +47,17 @@
import com.taobao.weex.dom.RenderActionContext;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.ui.animation.BackgroundColorProperty;
import com.taobao.weex.ui.animation.DimensionUpdateListener;
import com.taobao.weex.ui.animation.HeightProperty;
import com.taobao.weex.ui.animation.WXAnimationBean;
import com.taobao.weex.ui.animation.WXAnimationModule;
import com.taobao.weex.ui.animation.WidthProperty;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.view.border.BorderDrawable;
import com.taobao.weex.utils.SingleFunctionParser;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXResourceUtils;
import com.taobao.weex.utils.WXUtils;
import com.taobao.weex.utils.WXViewUtils;

import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -190,28 +189,28 @@ ObjectAnimator createAnimator(final View target, final int viewPortWidth) {
WXResourceUtils.getColor(style.backgroundColor)));
}
}
if (style.getPivot() != null) {
Pair<Float, Float> pair = style.getPivot();
target.setPivotX(pair.first);
target.setPivotY(pair.second);
}
animator = ObjectAnimator.ofPropertyValuesHolder(
target, holders.toArray(new PropertyValuesHolder[holders.size()]));
animator.setStartDelay(mAnimationBean.delay);

if (target.getLayoutParams() != null &&
(!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
DimensionUpdateListener listener = new DimensionUpdateListener(target);
ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
if (!TextUtils.isEmpty(style.width)) {
listener.setWidth(layoutParams.width,
(int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth));
holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width,
(int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)));
}
if (!TextUtils.isEmpty(style.height)) {
listener.setHeight(layoutParams.height,
(int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth));
holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height,
(int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)));
}
animator.addUpdateListener(listener);
}

if (style.getPivot() != null) {
Pair<Float, Float> pair = style.getPivot();
target.setPivotX(pair.first);
target.setPivotY(pair.second);
}
animator = ObjectAnimator.ofPropertyValuesHolder(
target, holders.toArray(new PropertyValuesHolder[holders.size()]));
animator.setStartDelay(mAnimationBean.delay);
return animator;
} else {
return null;
Expand All @@ -225,8 +224,8 @@ Animator.AnimatorListener createAnimatorListener(final WXSDKInstance instance, @
return new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (instance == null) {
WXLogUtils.e("RenderActionContextImpl-onAnimationEnd WXSDKInstance == null NPE");
if (instance == null || instance.isDestroy()) {
WXLogUtils.e("RenderActionContextImpl-onAnimationEnd WXSDKInstance == null NPE or instance is destroyed");
} else {
WXSDKManager.getInstance().callback(instance.getInstanceId(),
callBack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void executeDom(DOMActionContext context) {
mBorder = domObject.getBorder();

Map<String, Object> animationMap = new ArrayMap<>(2);
animationMap.put(WXDomObject.TRANSFORM, mData.remove(WXDomObject.TRANSFORM));
animationMap.put(WXDomObject.TRANSFORM_ORIGIN, mData.remove(WXDomObject.TRANSFORM_ORIGIN));
animationMap.put(WXDomObject.TRANSFORM, mData.get(WXDomObject.TRANSFORM));
animationMap.put(WXDomObject.TRANSFORM_ORIGIN, mData.get(WXDomObject.TRANSFORM_ORIGIN));

context.addAnimationForElement(mRef, animationMap);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.taobao.weex.ui.animation;


import android.view.ViewGroup.LayoutParams;

public class HeightProperty extends LayoutParamsProperty {

@Override
protected Integer getProperty(LayoutParams layoutParams) {
return layoutParams.height;
}

@Override
protected void setProperty(LayoutParams layoutParams, Integer expected) {
layoutParams.height = expected;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.taobao.weex.ui.animation;


import android.util.Property;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.view.IRenderResult;

/**
* android.util.IntProperty<T> cannot be applied here, as it is only added at API 24.
*/
abstract class LayoutParamsProperty extends Property<View, Integer> {

LayoutParamsProperty() {
super(Integer.class, "layoutParams");
}

@Override
public Integer get(View object) {
LayoutParams layoutParams;
if (object != null && (layoutParams = object.getLayoutParams()) != null) {
return getProperty(layoutParams);
}
return 0;
}

@Override
public void set(View object, Integer value) {
LayoutParams layoutParams;
if (object != null && (layoutParams = object.getLayoutParams()) != null) {
setProperty(layoutParams, value);
if (object instanceof IRenderResult) {
WXComponent component = ((IRenderResult) object).getComponent();
if (component != null) {
component.notifyNativeSizeChanged(layoutParams.width, layoutParams.height);
}
}
object.requestLayout();
}
}

protected abstract Integer getProperty(LayoutParams layoutParams);

protected abstract void setProperty(LayoutParams layoutParams, Integer expected);
}
Loading

0 comments on commit cd91163

Please sign in to comment.