diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPager.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPager.java index edd53230a1b..34d891e9983 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPager.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/HippyViewPager.java @@ -68,10 +68,9 @@ public void run() { // Reusable int array to be passed to method calls that mutate it in order to "return" two ints. private final int[] mScrollOffsetPair = new int[2]; private int mNestedScrollOffset = 0; - + //防抖时间 ms protected int mScrollEventThrottle = 0; - private void init(Context context, boolean isVertical) { setCallPageChangedOnFirstLayout(true); setEnableReLayoutOnAttachToWindow(false); 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 4a6dfbf63da..f386e149cac 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 @@ -132,10 +132,11 @@ public void setOverflow(HippyViewPager pager, String overflow) { pager.setOverflow(overflow); } - @HippyControllerProps(name = "scrollEventThrottle", defaultType = HippyControllerProps.NUMBER, defaultNumber = 30.0D) + @HippyControllerProps(name = "scrollEventThrottle", defaultType = HippyControllerProps.NUMBER, defaultNumber = 0) public void setScrollEventThrottle(HippyViewPager pager,int scrollEventThrottle) { pager.setScrollEventThrottle(scrollEventThrottle); } + private void resolveInvalidParams(@Nullable Promise promise) { if (promise != null) { String msg = "Invalid parameter!"; diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/ViewPagerPageChangeListener.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/ViewPagerPageChangeListener.java index 1320d8ba193..11dee4dd355 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/ViewPagerPageChangeListener.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/viewpager/ViewPagerPageChangeListener.java @@ -108,6 +108,8 @@ private void onScrollStateChangeToIdle() { params.put(PAGE_ITEM_POSITION, mLastPageIndex); EventUtils.sendComponentEvent(lastView, EventUtils.EVENT_PAGE_ITEM_DID_DISAPPEAR, params); mLastPageIndex = mCurrPageIndex; + //防抖只是针对onScroll事件。 状态事件不参与过滤,也不会被丢弃。 + // 状态变成idle只是重置mLastScrollEventTimeStamp,以便下次滑动开始时,重新计算。 mLastScrollEventTimeStamp = -1; }