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/offscreen page limit #4088

Merged
merged 3 commits into from
Oct 23, 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
7 changes: 7 additions & 0 deletions docs/api/hippy-react/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -503,6 +509,7 @@ import icon from './qb_icon_new.png';
| ------------------------ | ------------------------------------------------------------ | -------------------------------------------- | -------- |
| bounces | 是否开启回弹效果,默认 `true` | `boolean` | `iOS、Voltron` |
| initialPage | 指定一个数字,用于决定初始化后默认显示的页面 index,默认不指定的时候是0 | `number` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| offscreenPageLimit | 指定一个数字,用于设置最大挂载到view tree的page item数量,默认为1,如果在间隔较大的item之间切换遇到一些刷新闪动问题,可以尝试设置该属性为最大page item count来解决 | `number` | `Android` |
| scrollEnabled | 指定 ViewPager 是否可以滑动,默认为 `true` | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onPageSelected | 指定一个函数,当 page 被选中时进行回调。回调参数是一个 event 对象,回调参数: `position: number` - 表示即将滑到的目标 page 的索引 | `(obj: {position: number}) => void` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| onPageScroll | 指定一个函数,当 page 被滑动时进行回调。回调参数是一个 event 对象,回调参数 `position: number` - 表示即将滑到的目标 page 的索引,`offset: number` - 当前被选中的 page 的相对位移,取值范围 -1 到 1 | `(obj: {position: number, offset: number}) => void` | `Android、iOS、Web-Renderer、Voltron` |
Expand Down
3 changes: 3 additions & 0 deletions docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@

}
```

7. module注解HippyNativeModule中取消了线程属性的自定义 <br>
3.0中非JSI module调用将统一走hippy-module-Thread线程调用module对应接口,开发者可以根据自己的需要自行切换线程。

</br>

Expand Down
20 changes: 20 additions & 0 deletions docs/development/native-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Hippy SDK 现在所提供的 Adapter 包括:
- `HippyStorageAdapter`:数据库(KEY-VALUE)Adapter。
- `HippyExecutorSupplierAdapter`:线程池 Adapter。
- `HippyEngineMonitorAdapter`:Hippy 引擎状态监控 Adapter。
- `HippyFontScaleAdapter`:自定义字体 Adapter。


## HippyHttpAdapter
Expand Down Expand Up @@ -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);

```



<br/>
Expand Down
22 changes: 18 additions & 4 deletions docs/development/native-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
...
Expand All @@ -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)
Expand Down Expand Up @@ -105,6 +117,8 @@ public void helloNativeWithPromise(HippyMap hippyMap, Promise promise)
}
```



## 4. 注册Module

然后需要注册这个Module。需要在 `HippyPackage` 的 `getNativeModules` 方法中添加这个 Module,这样它才能在JS中被访问到。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<? extends HippyNativeModuleBase> mProvider;
private final Class<?> mClass;
@Nullable
Expand All @@ -61,7 +58,6 @@ public HippyNativeModuleInfo(@NonNull Class<?> cls,
if (annotation != null) {
mName = annotation.name();
mNames = annotation.names();
mThread = annotation.thread();
initImmediately(annotation);
}
}
Expand Down Expand Up @@ -96,10 +92,6 @@ public HippyNativeModuleBase getInstance() {
return mInstance;
}

public HippyNativeModule.Thread getThread() {
return mThread;
}

private void checkModuleMethods() {
if (mMethods != null) {
return;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void setOverflow(HippyViewPager pager, String overflow) {
pager.setOverflow(overflow);
}

@HippyControllerProps(name = "offscreenPageLimit", defaultNumber = 0, defaultType = HippyControllerProps.NUMBER)
public void setOffscreenPageLimit(HippyViewPager parent, int limit) {
parent.setOffscreenPageLimit(limit);
}

private void resolveInvalidParams(@Nullable Promise promise) {
if (promise != null) {
String msg = "Invalid parameter!";
Expand Down
Loading