Skip to content

Commit

Permalink
feat(android): compatible with custom event register
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed Sep 26, 2024
1 parent 80c5b5d commit 8474160
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
@Nullable Object params);
```

6. 自定义事件controller属性注册方式变更 <br>
由于3.0事件名称从2.0的驼峰写法统一转换为全小写命名,会导致之前开发者自定义事件无法接收到属性设置,需要在事件属性注解中将defaultType值改为HippyControllerProps.EVENT:

```java
@HippyControllerProps(name = "onMyEvent", defaultType = HippyControllerProps.EVENT, defaultBoolean = false)
public void setMyEvent(HippyScrollView scrollView, boolean isEnable) {

}
```

</br>

# 组件变更
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
String DEFAULT = "";
String ARRAY = "array";
String MAP = "map";
String EVENT = "event";

String name();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down

0 comments on commit 8474160

Please sign in to comment.