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

Commit

Permalink
Revert "[Android]support "wx" in animation and wxtext (#2783)"
Browse files Browse the repository at this point in the history
This reverts commit 1f54d46.
  • Loading branch information
lucky-chen committed Sep 19, 2019
1 parent fe41a75 commit b9c003a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 84 deletions.
9 changes: 5 additions & 4 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ public static int getFontSize(Map<String, Object> style,int viewPortW) {
if (style == null) {
return (int) WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,viewPortW);
}
int fontSize = (int) WXViewUtils.getRealPxByWidth(style.get(Constants.Name.FONT_SIZE),viewPortW);
int fontSize = WXUtils.getInt(style.get(Constants.Name.FONT_SIZE));
if (fontSize <= 0) {
fontSize = WXText.sDEFAULT_SIZE;
}
return fontSize;
return (int) WXViewUtils.getRealPxByWidth(fontSize,viewPortW);
}

public static String getFontFamily(Map<String, Object> style) {
Expand Down Expand Up @@ -213,11 +213,12 @@ public static int getLineHeight(Map<String, Object> style,int viewPortW){
if (style == null) {
return UNSET;
}
int lineHeight = (int)WXViewUtils.getRealPxByWidth(style.get(Constants.Name.LINE_HEIGHT),viewPortW);
int lineHeight = WXUtils.getInt(style.get(Constants.Name.LINE_HEIGHT));
if (lineHeight <= 0) {
lineHeight = UNSET;
return lineHeight;
}
return lineHeight;
return (int) WXViewUtils.getRealPxByWidth(lineHeight,viewPortW);
}

public float getBorderRadius() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,72 +443,72 @@ private PropertyValuesHolder createLayoutPropertyValueHolder(String property, Ob
switch (property){
case Constants.Name.WIDTH:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.WIDTH, mWXComponent.getLayoutWidth(),
WXViewUtils.getRealPxByWidth(value,0.0f, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloat(value, 0.0f), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.HEIGHT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.HEIGHT, mWXComponent.getLayoutHeight(),
WXViewUtils.getRealPxByWidth(value,0.0f, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloat(value, 0.0f), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.MARGIN_TOP:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.MARGIN_TOP, mWXComponent.getMargin().get(CSSShorthand.EDGE.TOP),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.MARGIN_LEFT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.MARGIN_LEFT, mWXComponent.getMargin().get(CSSShorthand.EDGE.LEFT),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.MARGIN_RIGHT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.MARGIN_RIGHT, mWXComponent.getMargin().get(CSSShorthand.EDGE.RIGHT),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.MARGIN_BOTTOM:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.MARGIN_BOTTOM, mWXComponent.getMargin().get(CSSShorthand.EDGE.BOTTOM),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.LEFT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.LEFT, mWXComponent.getLayoutPosition().getLeft(),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.RIGHT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.RIGHT, mWXComponent.getLayoutPosition().getRight(),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.BOTTOM:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.BOTTOM, mWXComponent.getLayoutPosition().getBottom(),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.TOP:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.TOP, mWXComponent.getLayoutPosition().getTop(),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.PADDING_TOP:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.PADDING_TOP, mWXComponent.getPadding().get(CSSShorthand.EDGE.TOP),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.PADDING_BOTTOM:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.PADDING_BOTTOM, mWXComponent.getPadding().get(CSSShorthand.EDGE.BOTTOM),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.PADDING_LEFT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.PADDING_LEFT, mWXComponent.getPadding().get(CSSShorthand.EDGE.LEFT),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
case Constants.Name.PADDING_RIGHT:{
holder = PropertyValuesHolder.ofFloat(Constants.Name.PADDING_RIGHT, mWXComponent.getPadding().get(CSSShorthand.EDGE.RIGHT),
WXViewUtils.getRealPxByWidth(value, mWXComponent.getViewPortWidth()));
WXViewUtils.getRealPxByWidth(WXUtils.getFloatByViewport(value, mWXComponent.getViewPortWidth()), mWXComponent.getViewPortWidth()));
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ ObjectAnimator createAnimator(final View target, final int viewPortWidth) {
ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
if (!TextUtils.isEmpty(style.width)) {
holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width,
(int) WXViewUtils.getRealPxByWidth(style.width, Float.NaN, viewPortWidth)));
(int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)));
}
if (!TextUtils.isEmpty(style.height)) {
holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height,
(int) WXViewUtils.getRealPxByWidth(style.width, Float.NaN, viewPortWidth)));
(int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class TransformParser {
private static final String FULL = "100%";
private static final String ZERO = "0%";
private static final String PX = "px";
private static final String WX = "wx";
private static final String DEG = "deg";
public static Map<String, List<Property<View,Float>>> wxToAndroidMap = new ArrayMap<>();

Expand Down Expand Up @@ -243,7 +242,7 @@ private Float parseCameraDistance(List<String> rawValue){
return new LinkedHashMap<>();
}

static Pair<Float, Float> parsePivot(@Nullable String transformOrigin,
private static Pair<Float, Float> parsePivot(@Nullable String transformOrigin,
int width, int height, int viewportW) {
if (!TextUtils.isEmpty(transformOrigin)) {
int firstSpace = transformOrigin.indexOf(FunctionParser.SPACE);
Expand Down Expand Up @@ -299,9 +298,10 @@ private static float parsePercentOrPx(String raw, int unit, int viewportW) {
int suffix;
if ((suffix = raw.lastIndexOf(WXUtils.PERCENT)) != -1) {
return parsePercent(raw.substring(0, suffix), unit, precision);
} else if ((suffix = raw.lastIndexOf(PX)) != -1) {
return WXViewUtils.getRealPxByWidth(WXUtils.fastGetFloat(raw.substring(0, suffix), precision),viewportW);
}
return WXViewUtils.getRealPxByWidth(raw,viewportW);

return WXViewUtils.getRealPxByWidth(WXUtils.fastGetFloat(raw, precision),viewportW);
}

private static float parsePercent(String percent, int unit, int precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,73 @@ public static class Style {
private List<PropertyValuesHolder> holders=new LinkedList<>();
private float cameraDistance = Float.MAX_VALUE;


private static Pair<Float, Float> parsePivot(@Nullable String transformOrigin,
int width, int height,int viewportW) {
if (!TextUtils.isEmpty(transformOrigin)) {
int firstSpace = transformOrigin.indexOf(FunctionParser.SPACE);
if (firstSpace != -1) {
int i = firstSpace;
for (; i < transformOrigin.length(); i++) {
if (transformOrigin.charAt(i) != FunctionParser.SPACE) {
break;
}
}
if (i < transformOrigin.length() && transformOrigin.charAt(i) != FunctionParser.SPACE) {
List<String> list = new ArrayList<>(2);
list.add(transformOrigin.substring(0, firstSpace).trim());
list.add(transformOrigin.substring(i, transformOrigin.length()).trim());
return parsePivot(list, width, height,viewportW);
}
}
}
return null;
}

private static Pair<Float, Float> parsePivot(@NonNull List<String> list, int width, int height,int viewportW) {
return new Pair<>(
parsePivotX(list.get(0), width,viewportW), parsePivotY(list.get(1), height,viewportW));
}

private static float parsePivotX(String x, int width,int viewportW) {
String value = x;
if (WXAnimationBean.Style.LEFT.equals(x)) {
value = ZERO;
} else if (WXAnimationBean.Style.RIGHT.equals(x)) {
value = FULL;
} else if (WXAnimationBean.Style.CENTER.equals(x)) {
value = HALF;
}
return parsePercentOrPx(value, width,viewportW);
}

private static float parsePivotY(String y, int height,int viewportW) {
String value = y;
if (WXAnimationBean.Style.TOP.equals(y)) {
value = ZERO;
} else if (WXAnimationBean.Style.BOTTOM.equals(y)) {
value = FULL;
} else if (WXAnimationBean.Style.CENTER.equals(y)) {
value = HALF;
}
return parsePercentOrPx(value, height,viewportW);
}

private static float parsePercentOrPx(String raw, int unit,int viewportW) {
final int precision = 1;
int suffix;
if ((suffix = raw.lastIndexOf(WXUtils.PERCENT)) != -1) {
return parsePercent(raw.substring(0, suffix), unit, precision);
} else if ((suffix = raw.lastIndexOf(PX)) != -1) {
return WXViewUtils.getRealPxByWidth(WXUtils.fastGetFloat(raw.substring(0, suffix), precision),viewportW);
}
return WXViewUtils.getRealPxByWidth(WXUtils.fastGetFloat(raw, precision),viewportW);
}

private static float parsePercent(String percent, int unit, int precision) {
return WXUtils.fastGetFloat(percent, precision) / 100 * unit;
}

private void resetToDefaultIfAbsent() {
for (Entry<Property<View, Float>, Float> entry : defaultMap.entrySet()) {
if (!transformMap.containsKey(entry.getKey())) {
Expand All @@ -133,7 +200,7 @@ private void resetToDefaultIfAbsent() {

public void init(@Nullable String transformOrigin,@Nullable String rawTransform,
final int width, final int height,int viewportW, WXSDKInstance instance){
pivot = TransformParser.parsePivot(transformOrigin,width,height,viewportW);
pivot = parsePivot(transformOrigin,width,height,viewportW);
transformMap.putAll(TransformParser.parseTransForm(instance.getInstanceId(), rawTransform, width,height,viewportW));
resetToDefaultIfAbsent();
if (transformMap.containsKey(CameraDistanceProperty.getInstance())) {
Expand Down
16 changes: 3 additions & 13 deletions android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public static boolean isUndefined(float value) {
return Float.isNaN(value);
}

/**
* Use {@link WXViewUtils#getRealPxByWidth(Object, float, int)} instead.
*/
@Deprecated

public static float getFloatByViewport(Object value, int viewport) {
if (value == null) {
return Float.NaN;
Expand Down Expand Up @@ -92,18 +89,11 @@ public static float getFloatByViewport(Object value, int viewport) {
}
return Float.NaN;
}
/**
* Use {@link WXViewUtils#getRealPxByWidth(Object, float, int)} instead.
*/
@Deprecated

public static float getFloat(Object value) {
return getFloat(value, Float.NaN);
}

/**
* Use {@link WXViewUtils#getRealPxByWidth(Object, float, int)} instead.
*/
@Deprecated
public static Float getFloat(Object value, @Nullable Float df) {
if (value == null) {
return df;
Expand Down Expand Up @@ -145,7 +135,7 @@ public static Float getFloat(Object value, @Nullable Float df) {
return df;
}

static float transferWx(String stringWithWXPostfix, int viewport) {
private static float transferWx(String stringWithWXPostfix, int viewport) {
if(null == stringWithWXPostfix) {
return 0;
}
Expand Down
46 changes: 0 additions & 46 deletions android/sdk/src/main/java/com/taobao/weex/utils/WXViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -270,19 +269,10 @@ public static int getScreenHeight(Context cxt) {
* @return the actual distance in the screen.
*/


/**
* Use {@link WXViewUtils#getRealPxByWidth(Object, float, int)} instead.
*/
@Deprecated
public static float getRealPxByWidth(float pxValue) {
return getRealPxByWidth(pxValue,750);
}

/**
* Use {@link WXViewUtils#getRealPxByWidth(Object, float, int)} instead.
*/
@Deprecated
public static float getRealPxByWidth(float pxValue,int customViewport) {
if (Float.isNaN(pxValue)) {
return pxValue;
Expand All @@ -294,42 +284,6 @@ public static float getRealPxByWidth(float pxValue,int customViewport) {
return realPx > 0.005 && realPx < 1 ? 1 : (float) Math.rint(realPx);
}
}
public static float getRealPxByWidth(Object value, float df, int customViewport) {
Float pxValue = df;
if (value == null) {
return df;
}
String temp = value.toString().trim();
if (Constants.Name.AUTO.equals(temp)
|| Constants.Name.UNDEFINED.equals(temp)
|| TextUtils.isEmpty(temp)) {
WXLogUtils.e("Argument Warning ! value is " + temp + "And default Value:" + df);
return df;
}
try {
if (temp.endsWith("wx")) {
pxValue = WXUtils.transferWx(temp, customViewport);
} else if (temp.endsWith("px")) {
temp = temp.substring(0, temp.indexOf("px"));
pxValue = Float.parseFloat(temp);
} else {
pxValue = Float.parseFloat(temp);
}
} catch (NumberFormatException nfe) {
WXLogUtils.e(WXLogUtils.getStackTrace(nfe));
} catch (Exception e) {
WXLogUtils.e(WXLogUtils.getStackTrace(e));
}
if (mUseWebPx) {
return (float) Math.rint(pxValue);
} else {
float realPx = (pxValue * getScreenWidth() / customViewport);
return realPx > 0.005 && realPx < 1 ? 1 : (float) Math.rint(realPx);
}
}
public static float getRealPxByWidth(Object value,int customViewport) {
return getRealPxByWidth(value,Float.NaN,customViewport);
}

@Deprecated
public static float getRealSubPxByWidth(float pxValue) {
Expand Down

0 comments on commit b9c003a

Please sign in to comment.