mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Observe decelerating scroll velocity for accurate direction reporting
This commit is contained in:
@@ -88,6 +88,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
NSMutableSet *_registeredSupplementaryKinds;
|
NSMutableSet *_registeredSupplementaryKinds;
|
||||||
|
|
||||||
|
CGPoint _deceleratingVelocity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If YES, the `UICollectionView` will reload its data on next layout pass so we should not forward any updates to it.
|
* If YES, the `UICollectionView` will reload its data on next layout pass so we should not forward any updates to it.
|
||||||
|
|
||||||
@@ -516,11 +518,16 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
- (ASScrollDirection)scrollDirection
|
- (ASScrollDirection)scrollDirection
|
||||||
{
|
{
|
||||||
CGPoint scrollVelocity = [self.panGestureRecognizer velocityInView:self.superview];
|
CGPoint scrollVelocity;
|
||||||
return [self scrollDirectionForVelocity:scrollVelocity];
|
if (self.isTracking) {
|
||||||
|
scrollVelocity = [self.panGestureRecognizer velocityInView:self.superview];
|
||||||
|
} else {
|
||||||
|
scrollVelocity = _deceleratingVelocity;
|
||||||
|
}
|
||||||
|
return [self _scrollDirectionForVelocity:scrollVelocity];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASScrollDirection)scrollDirectionForVelocity:(CGPoint)scrollVelocity
|
- (ASScrollDirection)_scrollDirectionForVelocity:(CGPoint)scrollVelocity
|
||||||
{
|
{
|
||||||
ASScrollDirection direction = ASScrollDirectionNone;
|
ASScrollDirection direction = ASScrollDirectionNone;
|
||||||
ASScrollDirection scrollableDirections = [self scrollableDirections];
|
ASScrollDirection scrollableDirections = [self scrollableDirections];
|
||||||
@@ -570,7 +577,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:[self scrollDirection]];
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(collectionView:willDisplayNodeForItemAtIndexPath:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(collectionView:willDisplayNodeForItemAtIndexPath:)]) {
|
||||||
[_asyncDelegate collectionView:self willDisplayNodeForItemAtIndexPath:indexPath];
|
[_asyncDelegate collectionView:self willDisplayNodeForItemAtIndexPath:indexPath];
|
||||||
@@ -629,6 +636,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
|
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
|
||||||
{
|
{
|
||||||
|
_deceleratingVelocity = CGPointMake(
|
||||||
|
scrollView.contentOffset.x - targetContentOffset->x,
|
||||||
|
scrollView.contentOffset.y - targetContentOffset->y
|
||||||
|
);
|
||||||
|
|
||||||
[self handleBatchFetchScrollingToOffset:*targetContentOffset];
|
[self handleBatchFetchScrollingToOffset:*targetContentOffset];
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
|
|
||||||
NSIndexPath *_contentOffsetAdjustmentTopVisibleRow;
|
NSIndexPath *_contentOffsetAdjustmentTopVisibleRow;
|
||||||
CGFloat _contentOffsetAdjustment;
|
CGFloat _contentOffsetAdjustment;
|
||||||
|
|
||||||
|
CGPoint _deceleratingVelocity;
|
||||||
|
|
||||||
CGFloat _nodesConstrainedWidth;
|
CGFloat _nodesConstrainedWidth;
|
||||||
BOOL _ignoreNodesConstrainedWidthChange;
|
BOOL _ignoreNodesConstrainedWidthChange;
|
||||||
@@ -563,14 +565,23 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
|
|
||||||
- (ASScrollDirection)scrollDirection
|
- (ASScrollDirection)scrollDirection
|
||||||
{
|
{
|
||||||
CGPoint scrollVelocity = [self.panGestureRecognizer velocityInView:self.superview];
|
CGPoint scrollVelocity;
|
||||||
|
if (self.isTracking) {
|
||||||
|
scrollVelocity = [self.panGestureRecognizer velocityInView:self.superview];
|
||||||
|
} else {
|
||||||
|
scrollVelocity = _deceleratingVelocity;
|
||||||
|
}
|
||||||
|
return [self _scrollDirectionForVelocity:scrollVelocity];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ASScrollDirection)_scrollDirectionForVelocity:(CGPoint)velocity
|
||||||
|
{
|
||||||
ASScrollDirection direction = ASScrollDirectionNone;
|
ASScrollDirection direction = ASScrollDirectionNone;
|
||||||
if (scrollVelocity.y > 0) {
|
if (velocity.y > 0) {
|
||||||
direction = ASScrollDirectionDown;
|
direction = ASScrollDirectionDown;
|
||||||
} else {
|
} else {
|
||||||
direction = ASScrollDirectionUp;
|
direction = ASScrollDirectionUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,6 +629,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
|
|
||||||
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
|
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
|
||||||
{
|
{
|
||||||
|
_deceleratingVelocity = CGPointMake(
|
||||||
|
scrollView.contentOffset.x - targetContentOffset->x,
|
||||||
|
scrollView.contentOffset.y - targetContentOffset->y
|
||||||
|
);
|
||||||
|
|
||||||
[self handleBatchFetchScrollingToOffset:*targetContentOffset];
|
[self handleBatchFetchScrollingToOffset:*targetContentOffset];
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user