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

* [android] fix flicker caused by coexistence of box-shadow and borde… #780

Merged
merged 3 commits into from
Oct 18, 2017
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 @@ -43,6 +43,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewOverlay;
import android.widget.FrameLayout;

import com.alibaba.fastjson.JSONArray;
Expand Down Expand Up @@ -509,6 +510,8 @@ private void setComponentLayoutParams(int realWidth, int realHeight, int realLef
setWidgetParams(widget, UIImp, rawOffset, realWidth, realHeight, realLeft, realRight, realTop,
realBottom);
} else if (mHost != null) {
// clear box shadow before host's size changed
clearBoxShadow();
if (mDomObj.isFixed()) {
setFixedHostLayoutParams(mHost, realWidth, realHeight, realLeft, realRight, realTop,
realBottom);
Expand All @@ -520,6 +523,8 @@ private void setComponentLayoutParams(int realWidth, int realHeight, int realLef
mPreRealLeft = realLeft;
mPreRealTop = realTop;
onFinishLayout();
// restore box shadow
updateBoxShadow();
}
}

Expand Down Expand Up @@ -759,22 +764,9 @@ protected boolean setProperty(String key, Object param) {
case Constants.Name.BORDER_TOP_RIGHT_RADIUS:
case Constants.Name.BORDER_BOTTOM_RIGHT_RADIUS:
case Constants.Name.BORDER_BOTTOM_LEFT_RADIUS:
final Float radius = WXUtils.getFloat(param,null);
final String finalKey = key;
Float radius = WXUtils.getFloat(param,null);
if (radius != null) {
if (this instanceof WXDiv && mHost != null) {
/* Hacked by moxun
Set border radius on ViewGroup will cause the Overlay to be cut and don't know why
Delay setting border radius can avoid the problem, and don't know why too, dog science…… */
mHost.postDelayed(new Runnable() {
@Override
public void run() {
setBorderRadius(finalKey, radius);
}
}, 64);
} else {
setBorderRadius(finalKey, radius);
}
setBorderRadius(key, radius);
}
return true;
case Constants.Name.BORDER_WIDTH:
Expand Down Expand Up @@ -872,6 +864,15 @@ protected void updateBoxShadow() {
return;
}

View target = mHost;
if (this instanceof WXVContainer) {
target = ((WXVContainer) this).getBoxShadowHost();
}

if (target == null) {
return;
}

float[] radii = new float[] {0, 0, 0, 0, 0, 0, 0, 0};
WXStyle style = getDomObject().getStyles();
if (style != null) {
Expand All @@ -898,12 +899,27 @@ protected void updateBoxShadow() {
}
}
}
BoxShadowUtil.setBoxShadow(mHost, boxShadow.toString(), radii, getInstance().getInstanceViewPortWidth());

BoxShadowUtil.setBoxShadow(target, boxShadow.toString(), radii, getInstance().getInstanceViewPortWidth());
} else {
WXLogUtils.w("Can not resolve styles");
}
}

protected void clearBoxShadow() {
View target = mHost;
if (this instanceof WXVContainer) {
target = ((WXVContainer) this).getBoxShadowHost();
}

if (target != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ViewOverlay overlay = target.getOverlay();
if (overlay != null) {
overlay.clear();
}
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void setAriaHidden(boolean isHidden) {
View host = getHostView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
*/
package com.taobao.weex.ui.component;

import android.content.Context;
import android.content.Intent;
import android.util.Pair;
import android.support.annotation.Nullable;
import android.util.Pair;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.Constants;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.utils.WXViewUtils;

import java.util.ArrayList;

/**
Expand All @@ -36,6 +40,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {

private static final String TAG="WXVContainer";
protected ArrayList<WXComponent> mChildren = new ArrayList<>();
private BoxShadowHost mBoxShadowHost;

@Deprecated
public WXVContainer(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) {
Expand Down Expand Up @@ -474,4 +479,22 @@ public void onRenderFinish(@RenderState int state) {
/********************************
* end hook Activity life cycle callback
********************************************************/

public @Nullable View getBoxShadowHost() {
if (mBoxShadowHost == null) {
mBoxShadowHost = new BoxShadowHost(getContext());
WXViewUtils.setBackGround(mBoxShadowHost, null);
mBoxShadowHost.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
getHostView().addView(mBoxShadowHost);
}
getHostView().removeView(mBoxShadowHost);
getHostView().addView(mBoxShadowHost);
return mBoxShadowHost;
}

private class BoxShadowHost extends View {
public BoxShadowHost(Context context) {
super(context);
}
}
}