diff --git a/docs/development/android-3.0-upgrade-guidelines.md b/docs/development/android-3.0-upgrade-guidelines.md index e49e5892009..31b7d8ce0d0 100644 --- a/docs/development/android-3.0-upgrade-guidelines.md +++ b/docs/development/android-3.0-upgrade-guidelines.md @@ -45,6 +45,16 @@ @Nullable Object params); ``` +6. 自定义事件controller属性注册方式变更
+ 由于3.0事件名称从2.0的驼峰写法统一转换为全小写命名,会导致之前开发者自定义事件无法接收到属性设置,需要在事件属性注解中将defaultType值改为HippyControllerProps.EVENT: + + ```java + @HippyControllerProps(name = "onMyEvent", defaultType = HippyControllerProps.EVENT, defaultBoolean = false) + public void setMyEvent(HippyScrollView scrollView, boolean isEnable) { + + } + ``` +
# 组件变更 diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyControllerProps.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyControllerProps.java index b8c6d0c96a3..625dc5553b7 100644 --- a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyControllerProps.java +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyControllerProps.java @@ -34,6 +34,7 @@ String DEFAULT = ""; String ARRAY = "array"; String MAP = "map"; + String EVENT = "event"; String name(); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java index 8631ba0c494..cd3b4547d43 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerUpdateManger.java @@ -16,6 +16,8 @@ package com.tencent.mtt.hippy.uimanager; +import static com.tencent.renderer.NativeRenderer.EVENT_PREFIX; + import android.graphics.Color; import android.view.View; @@ -112,6 +114,13 @@ private static void collectMethodHolder(@NonNull Class cls, propsMethodHolder.defaultBoolean = controllerProps.defaultBoolean(); propsMethodHolder.method = method; propsMethodHolder.hostClass = cls; + if (propsMethodHolder.defaultType.equals(HippyControllerProps.EVENT)) { + style = style.toLowerCase(); + // Compatible with events prefixed with on in old version + if (style.startsWith(EVENT_PREFIX)) { + style = style.substring(EVENT_PREFIX.length()); + } + } methodHolderMap.put(style, propsMethodHolder); } } @@ -170,6 +179,7 @@ private void invokePropMethod(@NonNull Object obj, @NonNull Object arg1, if (value == null) { switch (methodHolder.defaultType) { case HippyControllerProps.BOOLEAN: + case HippyControllerProps.EVENT: methodHolder.method.invoke(obj, arg1, methodHolder.defaultBoolean); break; case HippyControllerProps.NUMBER: diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java index d328690f033..8e97cc2b838 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java @@ -99,6 +99,7 @@ public class NativeRenderer extends Renderer implements NativeRender, NativeRend public static final String NODE_ID = "id"; public static final String NODE_INDEX = "index"; public static final String NODE_PROPS = "props"; + public static final String EVENT_PREFIX = "on"; private static final String TAG = "NativeRenderer"; private static final String NODE_PID = "pId"; private static final String NODE_DELETE_PROPS = "deleteProps"; @@ -107,7 +108,6 @@ public class NativeRenderer extends Renderer implements NativeRender, NativeRend private static final String LAYOUT_TOP = "top"; private static final String LAYOUT_WIDTH = "width"; private static final String LAYOUT_HEIGHT = "height"; - private static final String EVENT_PREFIX = "on"; private static final String SNAPSHOT_CREATE_NODE = "createNode"; private static final String SNAPSHOT_UPDATE_LAYOUT = "updateLayout"; private static final String PAINT_TYPE_KEY = "paintType";