[go: nahoru, domu]

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

Commit

Permalink
* [Android] Add JS Error Log in GraphicActionAddElement
Browse files Browse the repository at this point in the history
Set component.view.ContentDescription to ref if there is no contentDescription.
  • Loading branch information
YorkShen committed Jul 24, 2018
1 parent 011dc0a commit a9ac1ea
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.support.annotation.RestrictTo.Scope;
import android.text.TextUtils;
import com.taobao.weex.dom.CSSShorthand.CSSProperty;
import java.util.Arrays;

Expand Down Expand Up @@ -109,4 +111,10 @@ private void setInternal(@NonNull Enum<? extends CSSProperty> edge, float value)
private float getInternal(@NonNull Enum<? extends CSSProperty> edge){
return (edge == EDGE.ALL || edge == CORNER.ALL) ? 0 : values[edge.ordinal()];
}

@Override
@RestrictTo(Scope.LIBRARY)
public String toString() {
return TextUtils.isEmpty(values.toString()) ? "" : Arrays.toString(values);
}
}
8 changes: 8 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.taobao.weex.dom;

import android.support.annotation.RestrictTo;
import android.support.annotation.RestrictTo.Scope;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
Expand Down Expand Up @@ -581,4 +583,10 @@ public WXAttr clone() {
}
return wxAttr;
}

@RestrictTo(Scope.LIBRARY)
@Override
public String toString() {
return attr.toString();
}
}
7 changes: 7 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.annotation.RestrictTo.Scope;
import android.support.v4.util.ArrayMap;
import android.text.Layout;
import android.text.TextUtils;
Expand Down Expand Up @@ -545,4 +547,9 @@ public WXStyle clone(){
return style;
}

@Override
@RestrictTo(Scope.LIBRARY)
public String toString() {
return mStyles.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import android.support.annotation.RestrictTo;
import android.support.annotation.RestrictTo.Scope;
import android.support.annotation.WorkerThread;
import android.support.v4.util.ArrayMap;
import android.text.TextUtils;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.common.WXErrorCode;
Expand All @@ -31,6 +31,7 @@
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.utils.WXExceptionUtils;
import com.taobao.weex.utils.WXLogUtils;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -79,14 +80,59 @@ public GraphicActionAddElement(String pageId, String ref,
return;
}
}catch (ClassCastException e){
Map<String, String> ext = new ArrayMap<>();
WXComponent parent = WXSDKManager.getInstance().getWXRenderManager()
.getWXComponent(getPageId(), mParentRef);

if (mStyle != null && !mStyle.isEmpty()) {
ext.put("child.style", mStyle.toString());
}
if (parent != null && parent.getStyles() != null && !parent.getStyles().isEmpty()) {
ext.put("parent.style", parent.getStyles().toString());
}

if (mAttributes != null && !mAttributes.isEmpty()) {
ext.put("child.attr", mAttributes.toString());
}
if (parent != null && parent.getAttrs() != null && !parent.getAttrs().isEmpty()) {
ext.put("parent.attr", parent.getAttrs().toString());
}

if (mEvents != null && !mEvents.isEmpty()) {
ext.put("child.event", mEvents.toString());
}
if (parent != null && parent.getEvents() != null && !parent.getEvents().isEmpty()) {
ext.put("parent.event", parent.getEvents().toString());
}

if (mMargins != null && mMargins.length > 0) {
ext.put("child.margin", Arrays.toString(mMargins));
}
if (parent != null && parent.getMargin() != null) {
ext.put("parent.margin", parent.getMargin().toString());
}

if (mPaddings != null && mPaddings.length > 0) {
ext.put("child.padding", Arrays.toString(mPaddings));
}
if (parent != null && parent.getPadding() != null) {
ext.put("parent.padding", parent.getPadding().toString());
}

if (mBorders != null && mBorders.length > 0) {
ext.put("child.border", Arrays.toString(mBorders));
}
if (parent != null && parent.getBorder() != null) {
ext.put("parent.border", parent.getBorder().toString());
}

WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(),
WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE,
"GraphicActionAddElement",
String.format(Locale.ENGLISH,"You are trying to add a %s (ref: %s) to a %3$s (ref: %4$s), which is illegal as %3$s (ref: %4$s) is not a container",
componentType, ref,
WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType(),
parentRef),
null);
String.format(Locale.ENGLISH,"You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container",
componentType,
WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()),
ext);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,9 @@ protected void createViewImpl() {
}
if (mHost != null) {
mHost.setId(WXViewUtils.generateViewId());
if(TextUtils.isEmpty(mHost.getContentDescription()) && WXEnvironment.isApkDebugable()){
mHost.setContentDescription(getRef());
}
ComponentObserver observer;
if ((observer = getInstance().getComponentObserver()) != null) {
observer.onViewCreated(this, mHost);
Expand Down

0 comments on commit a9ac1ea

Please sign in to comment.