From 78e5fe07d4dfab0e4847516e308569b0772cbe2a Mon Sep 17 00:00:00 2001 From: maxli Date: Tue, 22 Oct 2024 21:12:14 +0800 Subject: [PATCH] feat(android): add offscreenPageLimit property for view pager --- docs/api/hippy-react/components.md | 1 + .../mtt/hippy/views/viewpager/HippyViewPagerController.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs/api/hippy-react/components.md b/docs/api/hippy-react/components.md index 42206575c11..f54368f9056 100644 --- a/docs/api/hippy-react/components.md +++ b/docs/api/hippy-react/components.md @@ -503,6 +503,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` | diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java index e8e0eefdf84..5f14430a828 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPagerController.java @@ -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!";