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

[WEEX-376][Core] Support layeroverflow event #1186

Merged
merged 1 commit into from
May 17, 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
10 changes: 0 additions & 10 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,6 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan
private ComponentObserver mComponentObserver;
private Map<String, GraphicActionAddElement> inactiveAddElementAction = new ArrayMap<>();

private boolean hasLayerLimit = false;

public void setLayerLimit(boolean hasLayerLimit) {
this.hasLayerLimit = hasLayerLimit;
}

public boolean isLayerLimit() {
return hasLayerLimit;
}

/**
* set make weexCore run in single process mode
* @param flag true means weexCore run in single process mode or multi process mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ public interface Event {

String ON_TRANSITION_END = "transitionEnd";

String LAYEROVERFLOW = "layeroverflow";

interface SLOT_LIFECYCLE {
String CREATE = "create";
String ATTACH = "attach";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public enum WXErrorCode {
*/
WX_RENDER_ERR_JS_CREATE_INSTANCE("-9600", "WX_RENDER_ERR_JS_CREATE_INSTANCE",ErrorType.RENDER_ERROR,ErrorGroup.JS),
WX_RENDER_ERR_JS_RUNTIME("-9601", "WX_RENDER_ERR for js error",ErrorType.RENDER_ERROR, ErrorGroup.JS),
WX_RENDER_ERR_LAYER_OVERFLOW("-9602", "WX_RENDER_ERR_LAYER_OVERFLOW", ErrorType.RENDER_ERROR, ErrorGroup.JS),
WX_RENDER_ERR_LAYER_OVERFLOW("-9602", "WX_RENDER_ERR_LAYER_OVERFLOW", ErrorType.NATIVE_ERROR, ErrorGroup.NATIVE),
WX_RENDER_ERR_CONTAINER_TYPE("-9611", "WX_RENDER_ERR_CONTAINER_TYPE", ErrorType.JS_ERROR,ErrorGroup.JS),


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.taobao.weex.ui.component;

import android.support.v4.util.ArraySet;
import com.taobao.weex.dom.CSSShorthand.CORNER;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -27,6 +26,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -296,7 +296,7 @@ private void applyEvents() {
*/
public void addEvent(final String type) {
if (mAppendEvents == null) {
mAppendEvents = new ArraySet<>();
mAppendEvents = new HashSet<>();
}
if (TextUtils.isEmpty(type) || mAppendEvents.contains(type)) {
return;
Expand Down Expand Up @@ -332,7 +332,7 @@ public void onFocusChange(boolean hasFocus) {
mGesture.setPreventMoveEvent(isPreventMove);
}
if (mGestureType == null) {
mGestureType = new ArraySet<>();
mGestureType = new HashSet<>();
}
mGestureType.add(type);
((WXGestureObservable)view).registerGestureListener(mGesture);
Expand Down Expand Up @@ -1184,7 +1184,11 @@ protected void setRole(String roleKey) {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setRoleDescription(finalRole);
try {
info.setRoleDescription(finalRole);
} catch (Exception e) {
WXLogUtils.e("SetRole failed!");
}
}
};
ViewCompat.setAccessibilityDelegate(host, delegate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,4 @@ public boolean intendToBeFlatContainer() {
public boolean isVirtualComponent() {
return !promoteToView(true);
}

@Override
protected boolean setProperty(String key, Object param) {
switch (key) {
case Constants.Name.LAYERLIMIT:
case Constants.Name.LAYER_LIMIT:
getInstance().setLayerLimit(WXUtils.getBoolean(param, false));
return true;
}
return super.setProperty(key, param);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ private WXSDKInstance createInstance() {
return sdkInstance;
}

sdkInstance.setLayerLimit(getInstance().isLayerLimit());

sdkInstance.renderByUrl(WXPerformance.DEFAULT,
url,
null, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.taobao.weex.utils.WXViewUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
* All container components must implement this class
Expand Down Expand Up @@ -349,6 +351,16 @@ public void notifyAppearStateChange(String wxEventType, String direction) {
}
}

public void notifyLayerOverFlow() {
if (containsEvent(Constants.Event.LAYEROVERFLOW)) {
Map<String, Object> params = new HashMap<>();
params.put("ref", getRef());
params.put("instanceid", getInstanceId());
fireEvent(Constants.Event.LAYEROVERFLOW, params);
}
}


/********************************************************
* begin hook Activity life cycle callback *
********************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* 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
Expand Down Expand Up @@ -101,30 +101,26 @@ protected boolean verifyDrawable(@NonNull Drawable who) {

@Override
protected void dispatchDraw(Canvas canvas) {
if (getComponent() != null && getComponent().getInstance().isLayerLimit()) {
try {
dispatchDrawInterval(canvas);
} catch (StackOverflowError e) {
reportLayerOverFlowError();
WXLogUtils.e("FlatGUI Crashed when dispatchDraw", WXLogUtils.getStackTrace(e));
}
} else {
try {
dispatchDrawInterval(canvas);
} catch (StackOverflowError e){
try {
dispatchDrawInterval(canvas);
} catch (Throwable e) {
if (getComponent() != null) {
getComponent().notifyLayerOverFlow();
reportLayerOverFlowError();
WXLogUtils.e("FlatGUI Crashed when dispatchDraw", WXLogUtils.getStackTrace(e));
}
WXLogUtils.e("Layer overflow limit error", WXLogUtils.getStackTrace(e));
}
}

private int reportLayerOverFlowError() {
int deep = calLayerDeep(this, 0);
WXExceptionUtils.commitCriticalExceptionRT(getComponent().getInstanceId(),
WXErrorCode.WX_RENDER_ERR_LAYER_OVERFLOW,
"draw android view",
WXErrorCode.WX_RENDER_ERR_LAYER_OVERFLOW.getErrorMsg() + "Layer overflow limit error: " + deep + " layers!",
null);
if (getComponent() != null) {
WXExceptionUtils.commitCriticalExceptionRT(getComponent().getInstanceId(),
WXErrorCode.WX_RENDER_ERR_LAYER_OVERFLOW,
"draw android view",
WXErrorCode.WX_RENDER_ERR_LAYER_OVERFLOW.getErrorMsg() + "Layer overflow limit error: " + deep + " layers!",
null);
}
return deep;
}

Expand All @@ -142,13 +138,6 @@ private void dispatchDrawInterval(Canvas canvas) {
}
}

static class LayerOverFlowLimitException extends RuntimeException {

public LayerOverFlowLimitException(String message) {
super(message);
}
}

private int calLayerDeep(View view, int deep) {
deep++;
if (view.getParent() != null && view.getParent() instanceof View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ private void drawBorders(Canvas canvas) {
mRectBounds.set(getBounds());
}

if (mBorderWidth == null)
return;

final float leftBorderWidth = mBorderWidth.get(EDGE.LEFT);
final float topBorderWidth = mBorderWidth.get(EDGE.TOP);
final float bottomBorderWidth = mBorderWidth.get(EDGE.BOTTOM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,18 @@ public static int getScreenHeight() {

public static int getScreenHeight(Context cxt) {
if(cxt!=null){
Resources res = cxt.getResources();
mScreenHeight =cxt.getResources().getDisplayMetrics().heightPixels;
if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
mScreenWidth = res
.getDisplayMetrics()
.widthPixels;
mScreenHeight = mScreenHeight > mScreenWidth ? mScreenHeight : mScreenWidth;
}
} else if (WXEnvironment.isApkDebugable()){
throw new WXRuntimeException("Error Context is null When getScreenHeight");
}
return mScreenHeight;

}

/**
Expand Down