From e73c63c7bad8d848c8b238427253de7481c81b1d Mon Sep 17 00:00:00 2001 From: maxli Date: Wed, 23 Oct 2024 15:19:42 +0800 Subject: [PATCH] fix(android): document improvement and update --- docs/api/hippy-react/components.md | 6 +++++ .../android-3.0-upgrade-guidelines.md | 3 +++ docs/development/native-adapter.md | 20 +++++++++++++++++ docs/development/native-module.md | 22 +++++++++++++++---- .../nativemodules/HippyNativeModuleInfo.java | 10 +-------- .../image/ImageLoaderModule.java | 4 ++-- .../hippy/annotation/HippyNativeModule.java | 7 ------ 7 files changed, 50 insertions(+), 22 deletions(-) diff --git a/docs/api/hippy-react/components.md b/docs/api/hippy-react/components.md index 7223bae82db..1921d47a0fc 100644 --- a/docs/api/hippy-react/components.md +++ b/docs/api/hippy-react/components.md @@ -157,6 +157,12 @@ import icon from './qb_icon_new.png'; > >* time: number: 可指定延迟多久后收起 PullHeader,单位ms +### expandPullHeader + +> 最低支持版本 `2.14.0` + +`() => void` 展开顶部下拉刷新条 PullHeader。当设置了`renderPullHeader`后,可以通过该方法来主动触发下拉刷新的效果。 + ### collapsePullFooter > 最低支持版本 `2.14.0` diff --git a/docs/development/android-3.0-upgrade-guidelines.md b/docs/development/android-3.0-upgrade-guidelines.md index 31b7d8ce0d0..829fde9e8e0 100644 --- a/docs/development/android-3.0-upgrade-guidelines.md +++ b/docs/development/android-3.0-upgrade-guidelines.md @@ -54,6 +54,9 @@ } ``` + +7. module注解HippyNativeModule中取消了线程属性的自定义
+ 3.0中非JSI module调用将统一走hippy-module-Thread线程调用module对应接口,开发者可以根据自己的需要自行切换线程。
diff --git a/docs/development/native-adapter.md b/docs/development/native-adapter.md index 5e3a83d294f..494e032ea0c 100644 --- a/docs/development/native-adapter.md +++ b/docs/development/native-adapter.md @@ -21,6 +21,7 @@ Hippy SDK 现在所提供的 Adapter 包括: - `HippyStorageAdapter`:数据库(KEY-VALUE)Adapter。 - `HippyExecutorSupplierAdapter`:线程池 Adapter。 - `HippyEngineMonitorAdapter`:Hippy 引擎状态监控 Adapter。 +- `HippyFontScaleAdapter`:自定义字体 Adapter。 ## HippyHttpAdapter @@ -55,6 +56,25 @@ Hippy SDK 提供默认空实现 `DefaultEngineMonitorAdapter`。当你需要查 用于支持开发者有自定义格式图片的解码需求,需要开发者自行提供接口类实例。 +## HippyFontScaleAdapter + +Hippy SDK 提供默认的实现 `DefaultFontScaleAdapter`,默认实现中未对字体做任何定制处理,如果需要加载自定义字体或者改变文字显示大小需要实现自定义font adapter并实现以下接口。 + +``` java +// 返回字体的缩放系数,开发者可以返回自定义缩放系数,来动态改变字体的显示大小 +float getFontScale(); + +// 通过该方法可以替换text中自定义表情字符 +CharSequence getEmoticonText(CharSequence text, int fontSize) + +// 根据font family和style返回自定义字体的文件路径 +String getCustomFontFilePath(String fontFamily, int style); + +// 根据font family和style返回自定义字体的Typaeface对象 +Typeface getCustomTypeface(String fontFamily, int style); + +``` +
diff --git a/docs/development/native-module.md b/docs/development/native-module.md index eddde6ffda1..364f53a8cad 100644 --- a/docs/development/native-module.md +++ b/docs/development/native-module.md @@ -43,13 +43,16 @@ public class TestModule extends HippyNativeModuleBase HippyNativeModuleBase 要求增加注解 `@HippyNativeModule` 。 -HippyNativeModule有两个注解参数: +HippyNativeModule注解参数: -- name:能力名称,js调用时需要通过此访问该能力。 -- thread:能力运行的线程。包括 `HippyNativeModule.Thread.DOM`(Dom线程)、`HippyNativeModule.Thread.MAIN`(主线程)、`HippyNativeModule.Thread.BRIDGE`(Bridge线程、默认值)。 +- name:module名称,js调用时需要通过此属性找到对应的module实例对象。 +- names:module别名,支持同一个module设置不同的名称。 +- init:默认为false,即module在首次调用的时候才会进行实例初始化,如果设置为true,在引擎创建时候就会马上创建实例并初始化 + +> **注意:init参数在非必要的情况下不要设置为true,否则可能增加引擎启动的耗时。** ``` java -@HippyNativeModule(name = "TestModule", thread = HippyNativeModule.Thread.BRIDGE) +@HippyNativeModule(name = "TestModule") public class TestModule extends HippyNativeModuleBase { ... @@ -65,8 +68,17 @@ public class TestModule extends HippyNativeModuleBase - Java基本数据类型。 - HippyArray:类似于ArrayList,线程非安全。 - HippyMap:类似于HashMap,线程非安全。 +- 基于JSValue的新数据类型:注解参数useJSValueType设置为true时适用。 - Promise:回调JS的触发器,通过 `resolve` 方法返回成功信息给JS。通过 `reject` 方法返回失败实现给JS。 +HippyMethod注解参数: + +- name:接口名称,js调用时需要通过此参数找到对应的接口信息,并进行反射调用。 +- isSync:是否为JSI接口,JSI为同步调用接口,会卡住js线程,只适用于数据结构简单且size较小的数据传输,[JSI特性介绍](feature/feature2.0/jsi.md) +- useJSValueType:接口参数是否使用新数据类型,默认为false,即使用老的HippyMap与HippyArray类型接收参数,设置为true以后参数需要使用基于JSValue为基类的扩展数据类型,[新数据类型介绍](development/type-mapping.md) + +> **注意:新数据类型不能与HippyMap或HippyArray相互嵌套混用, 否则会导致数据编解码产生错误。** + ```java @HippyMethod(name="log") public void log(String msg) @@ -105,6 +117,8 @@ public void helloNativeWithPromise(HippyMap hippyMap, Promise promise) } ``` + + ## 4. 注册Module 然后需要注册这个Module。需要在 `HippyPackage` 的 `getNativeModules` 方法中添加这个 Module,这样它才能在JS中被访问到。 diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/HippyNativeModuleInfo.java b/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/HippyNativeModuleInfo.java index 4cf1b6ad1f4..68dadcb7205 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/HippyNativeModuleInfo.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/HippyNativeModuleInfo.java @@ -23,7 +23,6 @@ import com.tencent.mtt.hippy.annotation.HippyMethod; import com.tencent.mtt.hippy.annotation.HippyNativeModule; -import com.tencent.mtt.hippy.annotation.HippyNativeModule.Thread; import com.tencent.mtt.hippy.common.HippyArray; import com.tencent.mtt.hippy.common.Provider; import com.tencent.mtt.hippy.modules.HippyModulePromise; @@ -35,7 +34,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -44,7 +42,6 @@ public final class HippyNativeModuleInfo { private static final String TAG = "HippyNativeModuleInfo"; private String mName; private String[] mNames; - private HippyNativeModule.Thread mThread = Thread.BRIDGE; private final Provider mProvider; private final Class mClass; @Nullable @@ -61,7 +58,6 @@ public HippyNativeModuleInfo(@NonNull Class cls, if (annotation != null) { mName = annotation.name(); mNames = annotation.names(); - mThread = annotation.thread(); initImmediately(annotation); } } @@ -96,10 +92,6 @@ public HippyNativeModuleBase getInstance() { return mInstance; } - public HippyNativeModule.Thread getThread() { - return mThread; - } - private void checkModuleMethods() { if (mMethods != null) { return; @@ -198,7 +190,7 @@ private boolean checkArgumentType(@NonNull Object args) { @Nullable private Object[] prepareArguments(@NonNull Object args, PromiseImpl promise) throws IllegalArgumentException { - if (mParamTypes == null || mParamTypes.length <= 0) { + if (mParamTypes == null || mParamTypes.length == 0) { return null; } if (!checkArgumentType(args)) { diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/image/ImageLoaderModule.java b/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/image/ImageLoaderModule.java index 0f7282ec50c..1b96fa7de70 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/image/ImageLoaderModule.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/image/ImageLoaderModule.java @@ -77,10 +77,10 @@ private void onFetchFailed(final String url, final Promise promise, @NonNull fin } private void handleFetchResult(final String url, final Promise promise, @NonNull final ResourceDataHolder dataHolder) { - byte[] bytes = dataHolder.getBytes(); - Bitmap bitmap = dataHolder.bitmap; LogUtils.d(TAG, "handleFetchResult: url " + url + ", result " + dataHolder.resultCode); if (dataHolder.resultCode == ResourceDataHolder.RESOURCE_LOAD_SUCCESS_CODE) { + byte[] bytes = dataHolder.getBytes(); + Bitmap bitmap = dataHolder.bitmap; if (bitmap != null && !bitmap.isRecycled()) { LogUtils.d(TAG, "handleFetchResult: url " + url + ", bitmap width " + bitmap.getWidth() + ", bitmap height " + bitmap.getHeight()); diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyNativeModule.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyNativeModule.java index b26043cd04d..6fca3093edf 100644 --- a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyNativeModule.java +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/annotation/HippyNativeModule.java @@ -28,16 +28,9 @@ @Target(TYPE) public @interface HippyNativeModule { - enum Thread { - BRIDGE, - MAIN - } - String name(); String[] names() default {}; - Thread thread() default Thread.BRIDGE; - boolean init() default false; }