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

[WEEX-376][Android] Fix div layeroverflow event #1191

Merged
merged 3 commits into from
May 22, 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
2 changes: 1 addition & 1 deletion android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ if(file('../license/LICENSE').exists()){
}

task weex_core_license(type: com.hierynomus.gradle.license.tasks.LicenseFormat){
source = fileTree(dir:"../../weex_core").include(['**/*.h','**/*.cpp']).
source = fileTree(dir:"../../weex_core").include(['**/*.h','**/*.cpp', '**/*.cc']).
exclude(['Source/rapidjson/**/*.h','Source/rapidjson/**/*.cpp',
'Source/android/base/base64/**/*.h','Source/android/base/base64/**/*.cpp',
'Source/android/jniprebuild/jniheader/*.h',
Expand Down
21 changes: 21 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan

private List<OnWXScrollListener> mWXScrollListeners;

private List<String> mLayerOverFlowListeners;

public List<String> getLayerOverFlowListeners() {
return mLayerOverFlowListeners;
}

public void addLayerOverFlowListener(String ref) {
if (mLayerOverFlowListeners == null)
mLayerOverFlowListeners = new ArrayList<>();
mLayerOverFlowListeners.add(ref);
}

public void removeLayerOverFlowListener(String ref) {
if (mLayerOverFlowListeners != null)
mLayerOverFlowListeners.remove(ref);
}

/**
* whether we are in preRender mode
* */
Expand Down Expand Up @@ -1339,6 +1356,10 @@ public synchronized void destroy() {
mComponentObserver = null;
}

if (mLayerOverFlowListeners != null) {
mLayerOverFlowListeners.clear();
}

getFlatUIContext().destroy();
mFlatGUIContext = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public interface Orientation {
int VERTICAL = 1;
}

public interface Weex {
String REF = "ref";
String INSTANCEID = "instanceid";
String TYPE = "type";
}

public interface Name {

String DEFAULT_WIDTH = "defaultWidth";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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.NATIVE_ERROR, ErrorGroup.NATIVE),
WX_RENDER_ERR_NULL_KEY("-9603", "WX_RENDER_ERR_NULL_KEY", 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,6 +18,7 @@
*/
package com.taobao.weex.ui.component;

import com.taobao.weex.common.WXErrorCode;
import com.taobao.weex.dom.CSSShorthand.CORNER;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -64,7 +65,6 @@
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.Menu;
import android.view.View;
Expand Down Expand Up @@ -115,6 +115,7 @@
import com.taobao.weex.ui.view.gesture.WXGestureType;
import com.taobao.weex.utils.BoxShadowUtil;
import com.taobao.weex.utils.WXDataStructureUtil;
import com.taobao.weex.utils.WXExceptionUtils;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXReflectionUtils;
import com.taobao.weex.utils.WXResourceUtils;
Expand Down Expand Up @@ -302,6 +303,10 @@ public void addEvent(final String type) {
return;
}
final View view = getRealView();

if (type.equals(Constants.Event.LAYEROVERFLOW))
addLayerOverFlowListener(getRef());

if (type.equals(Constants.Event.CLICK)) {
if (view == null) {
// wait next time to add.
Expand Down Expand Up @@ -661,25 +666,32 @@ public void updateProperties(Map<String, Object> props) {
String key = entry.getKey();
Object param = entry.getValue();
String value = WXUtils.getString(param, null);
if (TextUtils.isEmpty(value)) {
param = convertEmptyProperty(key, value);
}
if (!setProperty(key, param)) {
if (mHolder == null) {
return;

if (key == null) {
WXExceptionUtils.commitCriticalExceptionRT(getInstanceId(),
WXErrorCode.WX_RENDER_ERR_NULL_KEY, "updateProperties",
WXErrorCode.WX_RENDER_ERR_NULL_KEY.getErrorMsg(), null);
} else {
if (TextUtils.isEmpty(value)) {
param = convertEmptyProperty(key, value);
}
Invoker invoker = mHolder.getPropertyInvoker(key);
if (invoker != null) {
try {
Type[] paramClazzs = invoker.getParameterTypes();
if (paramClazzs.length != 1) {
WXLogUtils.e("[WXComponent] setX method only one parameter:" + invoker);
return;
if (!setProperty(key, param)) {
if (mHolder == null) {
return;
}
Invoker invoker = mHolder.getPropertyInvoker(key);
if (invoker != null) {
try {
Type[] paramClazzs = invoker.getParameterTypes();
if (paramClazzs.length != 1) {
WXLogUtils.e("[WXComponent] setX method only one parameter:" + invoker);
return;
}
param = WXReflectionUtils.parseArgument(paramClazzs[0], param);
invoker.invoke(this, param);
} catch (Exception e) {
WXLogUtils.e("[WXComponent] updateProperties :" + "class:" + getClass() + "method:" + invoker.toString() + " function " + WXLogUtils.getStackTrace(e));
}
param = WXReflectionUtils.parseArgument(paramClazzs[0], param);
invoker.invoke(this, param);
} catch (Exception e) {
WXLogUtils.e("[WXComponent] updateProperties :" + "class:" + getClass() + "method:" + invoker.toString() + " function " + WXLogUtils.getStackTrace(e));
}
}
}
Expand Down Expand Up @@ -1393,6 +1405,10 @@ public final void removeEvent(String type) {
if (getEvents() == null || mAppendEvents == null || mGestureType == null) {
return;
}

if (type.equals(Constants.Event.LAYEROVERFLOW))
removeLayerOverFlowListener(getRef());

getEvents().remove(type);
mAppendEvents.remove(type);//only clean append events, not dom's events.
mGestureType.remove(type);
Expand Down Expand Up @@ -2267,4 +2283,14 @@ public void updateNativeStyles(Map<String, Object> dynamic){
updateNativeStyle(objectEntry.getKey(), objectEntry.getValue());
}
}

public void addLayerOverFlowListener(String ref) {
if (getInstance() != null)
getInstance().addLayerOverFlowListener(ref);
}

public void removeLayerOverFlowListener(String ref) {
if (getInstance() != null)
getInstance().removeLayerOverFlowListener(ref);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -501,4 +500,16 @@ private void destoryNestInstance(){
+ " strategy " + this.strategy);
}
}

@Override
public void addLayerOverFlowListener(String ref) {
if (mNestedInstance != null)
mNestedInstance.addLayerOverFlowListener(getRef());
}

@Override
public void removeLayerOverFlowListener(String ref) {
if (mNestedInstance != null)
mNestedInstance.removeLayerOverFlowListener(ref);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,6 @@ 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 @@ -28,7 +28,11 @@
import android.view.View;
import android.widget.FrameLayout;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.common.Constants;
import com.taobao.weex.common.WXErrorCode;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXDiv;
import com.taobao.weex.ui.flat.widget.Widget;
import com.taobao.weex.ui.view.gesture.WXGesture;
Expand All @@ -37,7 +41,9 @@
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXViewUtils;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* FrameLayout wrapper
Expand Down Expand Up @@ -105,7 +111,7 @@ protected void dispatchDraw(Canvas canvas) {
dispatchDrawInterval(canvas);
} catch (Throwable e) {
if (getComponent() != null) {
getComponent().notifyLayerOverFlow();
notifyLayerOverFlow();
reportLayerOverFlowError();
}
WXLogUtils.e("Layer overflow limit error", WXLogUtils.getStackTrace(e));
Expand Down Expand Up @@ -145,4 +151,24 @@ private int calLayerDeep(View view, int deep) {
}
return deep;
}

public void notifyLayerOverFlow() {
if (getComponent() == null)
return;

WXSDKInstance instance = getComponent().getInstance();
if (instance == null)
return;

if (instance.getLayerOverFlowListeners() == null)
return;

for (String ref : instance.getLayerOverFlowListeners()) {
WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(instance.getInstanceId(), ref);
Map<String, Object> params = new HashMap<>();
params.put(Constants.Weex.REF, ref);
params.put(Constants.Weex.INSTANCEID, component.getInstanceId());
component.fireEvent(Constants.Event.LAYEROVERFLOW, params);
}
}
}
22 changes: 22 additions & 0 deletions weex_core/Source/IPC/Buffering/IPCBuffer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed 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.
*/

/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/

#ifndef IPCBUFFER_H
#define IPCBUFFER_H
#include <stddef.h>
Expand Down
22 changes: 22 additions & 0 deletions weex_core/Source/IPC/IPCArguments.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed 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.
*/

/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/

#ifndef IPCARGUMENTS_H
#define IPCARGUMENTS_H
#include "IPCType.h"
Expand Down
22 changes: 22 additions & 0 deletions weex_core/Source/IPC/IPCByteArray.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed 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.
*/

/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/

#ifndef IPCBYTEARRAY_H
#define IPCBYTEARRAY_H
#include <stddef.h>
Expand Down
22 changes: 22 additions & 0 deletions weex_core/Source/IPC/IPCCheck.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed 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.
*/

/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/

#if !defined(NDEBUG)
#include "IPCCheck.h"
#include <android/log.h>
Expand Down
Loading