Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Dec 18, 2024
1 parent 0dfe3a0 commit fa5802d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,9 @@ - (BOOL)_shouldDisableScrollInteraction
return NO;
}

- (void)_setScrollViewMetrics:(ScrollViewEventEmitter::Metrics &)metrics
- (ScrollViewEventEmitter::Metrics)_scrollViewMetrics
{
auto metrics = ScrollViewEventEmitter::Metrics{};
metrics.contentSize = RCTSizeFromCGSize(_scrollView.contentSize);
metrics.contentOffset = RCTPointFromCGPoint(_scrollView.contentOffset);
metrics.contentInset = RCTEdgeInsetsFromUIEdgeInsets(_scrollView.contentInset);
Expand All @@ -542,13 +543,18 @@ - (void)_setScrollViewMetrics:(ScrollViewEventEmitter::Metrics &)metrics
if (_layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) {
metrics.contentOffset.x = metrics.contentSize.width - metrics.containerSize.width - metrics.contentOffset.x;
}

return metrics;
}

- (ScrollViewEventEmitter::Metrics)_scrollViewMetrics
- (ScrollViewEventEmitter::EndDragMetrics)_scrollViewMetricsWithVelocity:(CGPoint)velocity
andTargetContentOffset:(CGPoint)targetContentOffset
{
auto metrics = ScrollViewEventEmitter::Metrics{};
[self _setScrollViewMetrics:metrics];

ScrollViewEventEmitter::EndDragMetrics metrics = [self _scrollViewMetrics];
metrics.targetContentOffset.x = targetContentOffset.x;
metrics.targetContentOffset.y = targetContentOffset.y;
metrics.velocity.x = velocity.x;
metrics.velocity.y = velocity.y;
return metrics;
}

Expand Down Expand Up @@ -612,12 +618,7 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
return;
}

auto metrics = ScrollViewEventEmitter::EndDragMetrics{};
[self _setScrollViewMetrics:metrics];
metrics.targetContentOffset.x = targetContentOffset->x;
metrics.targetContentOffset.y = targetContentOffset->y;
metrics.velocity.x = velocity.x;
metrics.velocity.y = velocity.y;
auto metrics = [self _scrollViewMetricsWithVelocity:velocity andTargetContentOffset:*targetContentOffset];

static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onScrollEndDrag(metrics);
}
Expand Down Expand Up @@ -786,8 +787,7 @@ - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UI
return;
}

auto metrics = ScrollViewEventEmitter::EndDragMetrics{};
[self _setScrollViewMetrics:metrics];
auto metrics = [self _scrollViewMetricsWithVelocity:{} andTargetContentOffset:{}];
static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onScrollEndDrag(metrics);

[self _updateStateWithContentOffset];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct ScrollEndDragEvent : public ScrollEvent {

ScrollEndDragEvent() = default;

ScrollEndDragEvent(const ScrollEvent& scrollEvent)
: ScrollEvent(scrollEvent), targetContentOffset({}), velocity({}) {}

folly::dynamic asDynamic() const;

/*
Expand Down

0 comments on commit fa5802d

Please sign in to comment.