diff --git a/ios/sdk/component/viewPager/HippyViewPager.m b/ios/sdk/component/viewPager/HippyViewPager.m index 644412ecd11..81eee462801 100644 --- a/ios/sdk/component/viewPager/HippyViewPager.m +++ b/ios/sdk/component/viewPager/HippyViewPager.m @@ -27,6 +27,13 @@ #import "HippyViewPagerItem.h" #import "HippyI18nUtils.h" + +static NSString *const HippyPageScrollStateKey = @"pageScrollState"; +static NSString *const HippyPageScrollStateIdle = @"idle"; +static NSString *const HippyPageScrollStateSettling = @"settling"; +static NSString *const HippyPageScrollStateDragging = @"dragging"; + + @interface HippyViewPager () @property (nonatomic, strong) NSMutableArray *viewPagerItems; @property (nonatomic, assign) BOOL isScrolling; @@ -181,8 +188,16 @@ - (void)setPage:(NSInteger)pageNumber animated:(BOOL)animated { self.targetContentOffsetX = CGRectGetMinX(theItem.frame); [self setContentOffset:theItem.frame.origin animated:animated]; [self invokePageSelected:pageNumber]; + + // only send state when use no animation if (self.onPageScrollStateChanged) { - self.onPageScrollStateChanged(@{ @"pageScrollState": @"idle" }); + if (animated) { + HippyLogTrace(@"[HippyViewPager] settling --- (setPage withAnimation)"); + self.onPageScrollStateChanged(@{ HippyPageScrollStateKey: HippyPageScrollStateSettling }); + } else { + HippyLogTrace(@"[HippyViewPager] idle ~~~~~~ (setPage withoutAnimation)"); + self.onPageScrollStateChanged(@{ HippyPageScrollStateKey: HippyPageScrollStateIdle }); + } } } @@ -225,7 +240,8 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { } } if (self.onPageScrollStateChanged) { - self.onPageScrollStateChanged(@{ @"pageScrollState": @"dragging" }); + HippyLogTrace(@"[HippyViewPager] dragging --- (BeginDragging)"); + self.onPageScrollStateChanged(@{ HippyPageScrollStateKey : HippyPageScrollStateDragging }); } } @@ -280,8 +296,9 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL self.isScrolling = NO; } if (self.onPageScrollStateChanged) { - NSString *state = decelerate ? @"settling" : @"idle"; - self.onPageScrollStateChanged(@{ @"pageScrollState": state }); + NSString *state = decelerate ? HippyPageScrollStateSettling : HippyPageScrollStateIdle; + HippyLogTrace(@"[HippyViewPager] %@ ??? (EndDragging)", state); + self.onPageScrollStateChanged(@{ HippyPageScrollStateKey : state }); } } @@ -295,7 +312,8 @@ - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { if (self.onPageScrollStateChanged) { - self.onPageScrollStateChanged(@{ @"pageScrollState": @"idle" }); + HippyLogTrace(@"[HippyViewPager] idle ~~~~~~ (EndDecelerating)"); + self.onPageScrollStateChanged(@{ HippyPageScrollStateKey : HippyPageScrollStateIdle }); } self.isScrolling = NO; for (NSObject *scrollViewListener in _scrollViewListener) { @@ -306,6 +324,11 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { } - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { + if (self.onPageScrollStateChanged) { + HippyLogTrace(@"[HippyViewPager] idle ~~~~~~ (DidEndScrollingAnimation)"); + self.onPageScrollStateChanged(@{ HippyPageScrollStateKey : HippyPageScrollStateIdle }); + } + for (NSObject *scrollViewListener in _scrollViewListener) { if ([scrollViewListener respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)]) { [scrollViewListener scrollViewDidEndScrollingAnimation:scrollView]; @@ -454,8 +477,7 @@ - (void)layoutSubviews { [self setPage:self.initialPage animated:NO]; _didFirstTimeLayout = YES; self.needsResetPageIndex= NO; - } - else { + } else { if (self.needsResetPageIndex) { [self setPage:_lastPageIndex animated:NO]; self.needsResetPageIndex= NO;