Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): compatible with custom event register #4048

Merged
merged 1 commit into from
Sep 26, 2024
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: 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
Loading