Skip to content

Commit

Permalink
feat(renderer): reset time when setPage and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinwli committed Nov 7, 2023
1 parent 12880a1 commit 9d65d5e
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ - (void)setPage:(NSInteger)pageNumber animated:(BOOL)animated {
HippyLogWarn(@"Error In ViewPager setPage: pageNumber invalid");
return;
}

// reset time,Avoid the next event not send
self._lastScrollDispatchTime = -1;
_lastPageIndex = pageNumber;
UIView *theItem = self.viewPagerItems[pageNumber];
self.targetContentOffsetX = CGRectGetMinX(theItem.frame);
Expand Down Expand Up @@ -205,7 +206,6 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
} else {
self.mHasUnsentScrollEvent = true;
}

}

for (NSObject<UIScrollViewDelegate> *scrollViewListener in _scrollViewListener) {
Expand Down Expand Up @@ -250,7 +250,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
self.isScrolling = NO;
}

if(!decelerate) {
if (!decelerate) {
[self onScrollIdle];
}
if (self.onPageScrollStateChanged) {
Expand Down Expand Up @@ -514,21 +514,20 @@ - (bool)checkSendOnScrollEvent {
return false;
}

- (void)sendOnPageScrollEvent: (NSUInteger)position positionOffset:(CGFloat) positionOffset{
- (void)sendOnPageScrollEvent:(NSUInteger)position positionOffset:(CGFloat)positionOffset {
self.mHasUnsentScrollEvent = false;
self.onPageScroll(@{
@"position": @(position),
@"offset": @(positionOffset),
@"position" : @(position),
@"offset" : @(positionOffset),
});
}

- (void)onScrollIdle {
//reset on scroll idle
// reset on scroll idle
self._lastScrollDispatchTime = -1;
if(self.mHasUnsentScrollEvent) {
if (self.mHasUnsentScrollEvent) {
self.mHasUnsentScrollEvent = false;
[self sendOnPageScrollEvent:self.onPageScrolledPosition positionOffset:self.onPageScrollPositionOffset];
}
}

@end

0 comments on commit 9d65d5e

Please sign in to comment.