From f2166c358b3ed0fb3e9dd55d2bed9b7fe7a6a05e Mon Sep 17 00:00:00 2001 From: Anna Tang Date: Tue, 10 Aug 2021 19:58:31 -0700 Subject: [PATCH] Scroll to focused media below header Summary: ## Context We want the post-tap headers to be sticky so that context is maintained as the user scrolls down the media chain. ## In this diff When clicking on a media tile in a media module (rather than the See All CTA), the sticky header was covering part of the media post's header. We want to shift the scroll-to view down so that the sticky header is sitting on top of the media post's header. - Create new version of IGListAdapter API's `scrollToObject` function that contains an additional parameter `additionalYOffset` - Call new `scrollToObject` function with offset of 48.0f (height of header) ## In this stack Add sticky headers for post-taps, excluding SERP Reviewed By: maxolls Differential Revision: D29961626 fbshipit-source-id: c8644cc868e8d7ec92cad5f6c7742d93d001f67d --- CHANGELOG.md | 19 +++++++ Source/IGListKit/IGListAdapter.h | 8 ++- Source/IGListKit/IGListAdapter.m | 3 ++ Tests/IGListAdapterTests.m | 92 ++++++++++++++++---------------- 4 files changed, 75 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b46e387..dd1019eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,25 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Introducing `allowsBackgroundDiffing` on `IGListAdapterUpdater`! This property lets the updater perform the diffing on a background thread. Originally introduced by Ryan Nystrom a while back. [Maxime Ollivier](https://github.com/maxolls) (tbd) +- Updated `scrollToObject:` method in `IGListAdapter` to include a new parameter `additionalOffset` to handle shifting the final scroll position by some vertical or horizontal offset depending on the scroll direction. This allows the object to be shown at the correct position when it is scrolled to in a list with sticky headers. + +```objc +// OLD +- (void)scrollToObject:(id)object + supplementaryKinds:(nullable NSArray *)supplementaryKinds + scrollDirection:(UICollectionViewScrollDirection)scrollDirection + scrollPosition:(UICollectionViewScrollPosition)scrollPosition + animated:(BOOL)animated; + +// NEW +- (void)scrollToObject:(id)object + supplementaryKinds:(nullable NSArray *)supplementaryKinds + scrollDirection:(UICollectionViewScrollDirection)scrollDirection + scrollPosition:(UICollectionViewScrollPosition)scrollPosition + additionalOffset:(CGPoint)additionalOffset + animated:(BOOL)animated; +``` + ### Enhancements - Added `shouldSelectItemAtIndex:` to `IGListSectionController` . [dirtmelon](https://github.com/dirtmelon) diff --git a/Source/IGListKit/IGListAdapter.h b/Source/IGListKit/IGListAdapter.h index fa6192d6e..f0d20a4b3 100644 --- a/Source/IGListKit/IGListAdapter.h +++ b/Source/IGListKit/IGListAdapter.h @@ -248,19 +248,25 @@ NS_SWIFT_NAME(ListAdapter) @param supplementaryKinds The types of supplementary views in the section. @param scrollDirection An option indicating the direction to scroll. @param scrollPosition An option that specifies where the item should be positioned when scrolling finishes. + @param additionalOffset Additional offset amount from the scroll position. @param animated A flag indicating if the scrolling should be animated. + + @note The additional offset amount is to shift the final scroll position by some horizontal or vertical amount + depending on the scroll direction. This is necessary when scrolling to an object on a view with sticky headers, since + the sticky header would otherwise cover the top portion of the object. */ - (void)scrollToObject:(id)object supplementaryKinds:(nullable NSArray *)supplementaryKinds scrollDirection:(UICollectionViewScrollDirection)scrollDirection scrollPosition:(UICollectionViewScrollPosition)scrollPosition + additionalOffset:(CGFloat)additionalOffset animated:(BOOL)animated; /** Returns the size of a cell at the specified index path. @param indexPath The index path of the cell. - +å @return The size of the cell. */ - (CGSize)sizeForItemAtIndexPath:(NSIndexPath *)indexPath; diff --git a/Source/IGListKit/IGListAdapter.m b/Source/IGListKit/IGListAdapter.m index ecfc29867..752128eda 100644 --- a/Source/IGListKit/IGListAdapter.m +++ b/Source/IGListKit/IGListAdapter.m @@ -199,6 +199,7 @@ - (void)scrollToObject:(id)object supplementaryKinds:(NSArray *)supplementaryKinds scrollDirection:(UICollectionViewScrollDirection)scrollDirection scrollPosition:(UICollectionViewScrollPosition)scrollPosition + additionalOffset:(CGFloat)additionalOffset animated:(BOOL)animated { IGAssertMainThread(); IGParameterAssert(object != nil); @@ -297,6 +298,7 @@ - (void)scrollToObject:(id)object } const CGFloat maxOffsetX = collectionView.contentSize.width - collectionView.frame.size.width + contentInset.right; const CGFloat minOffsetX = -contentInset.left; + contentOffset.x += additionalOffset; contentOffset.x = MIN(contentOffset.x, maxOffsetX); contentOffset.x = MAX(contentOffset.x, minOffsetX); break; @@ -324,6 +326,7 @@ - (void)scrollToObject:(id)object const CGFloat maxHeight = collectionView.collectionViewLayout.collectionViewContentSize.height; const CGFloat maxOffsetY = maxHeight - collectionView.frame.size.height + contentInset.bottom; const CGFloat minOffsetY = -contentInset.top; + contentOffset.y += additionalOffset; contentOffset.y = MIN(contentOffset.y, maxOffsetY); contentOffset.y = MAX(contentOffset.y, minOffsetY); break; diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index d21e041a9..d5ba206d0 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -674,18 +674,18 @@ - (void)test_whenScrollVerticallyToItem { self.dataSource.objects = @[@1, @2, @3, @4, @5, @6]; [self.adapter reloadDataWithCompletion:nil]; XCTAssertEqual([self.collectionView numberOfSections], 6); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@2 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@2 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 10); - [self.adapter scrollToObject:@3 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@3 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 30); - [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; // Content height minus collection view height is 110, can't scroll more than that IGAssertEqualPoint([self.collectionView contentOffset], 0, 110); - [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; + [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionCenteredVertically additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 110); - [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 110); } @@ -693,11 +693,11 @@ - (void)test_whenScrollVerticallyToItemInASectionWithNoCellsAndNoSupplymentaryVi self.dataSource.objects = @[@1, @0, @300]; [self.adapter reloadDataWithCompletion:nil]; XCTAssertEqual([self.collectionView numberOfSections], 3); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@0 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@0 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@300 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@300 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 10); } @@ -716,38 +716,38 @@ - (void)test_whenScrollVerticallyToItemInASectionWithNoCellsButAHeaderSupplyment [self.adapter performUpdatesAnimated:NO completion:nil]; XCTAssertEqual([self.collectionView numberOfSections], 3); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@0 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@0 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@0 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop animated:NO]; + [self.adapter scrollToObject:@0 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 10); - [self.adapter scrollToObject:@300 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@300 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 20); } - (void)test_whenScrollVerticallyToItemWithPositionning { self.dataSource.objects = @[@1, @100, @200]; [self.adapter reloadDataWithCompletion:nil]; - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionCenteredVertically additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 10); - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 10); - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionCenteredVertically additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 460); - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 910); - [self.adapter scrollToObject:@200 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@200 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, self.collectionView.contentSize.height - self.collectionView.frame.size.height); } @@ -758,24 +758,24 @@ - (void)test_whenScrollVerticallyToBottom_withContentInsets_thatBottomFlushWithC // no insets self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView layoutIfNeeded]; - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 900); // top 100 self.collectionView.contentInset = UIEdgeInsetsMake(100, 0, 0, 0); - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 900); // bottom 100 self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0); [self.collectionView layoutIfNeeded]; - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 900 + 100); // top 50, bottom 100 self.collectionView.contentInset = UIEdgeInsetsMake(50, 0, 100, 0); [self.collectionView layoutIfNeeded]; - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionBottom additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 900 + 100); } @@ -790,24 +790,24 @@ - (void)test_whenScrollHorizontalToRight_withContentInsets_thatRightFlushWithCol // no insets self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView layoutIfNeeded]; - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 900, 0); // left 100 self.collectionView.contentInset = UIEdgeInsetsMake(0, 100, 0, 0); - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 900, 0); // right 100 self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 100); [self.collectionView layoutIfNeeded]; - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 900 + 100, 0); // left 50, right 100 self.collectionView.contentInset = UIEdgeInsetsMake(0, 50, 0, 100); [self.collectionView layoutIfNeeded]; - [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight animated:NO]; + [self.adapter scrollToObject:@100 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 900 + 100, 0); } @@ -819,18 +819,18 @@ - (void)test_whenScrollHorizontallyToItem { self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; [self.adapter reloadDataWithCompletion:nil]; XCTAssertEqual([self.collectionView numberOfSections], 6); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@2 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@2 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 10, 0); - [self.adapter scrollToObject:@3 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@3 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 30, 0); - [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; // Content width minus collection view width is 110, can't scroll more than that IGAssertEqualPoint([self.collectionView contentOffset], 110, 0); - [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO]; + [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionCenteredHorizontally additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 110, 0); - [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight animated:NO]; + [self.adapter scrollToObject:@6 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionHorizontal scrollPosition:UICollectionViewScrollPositionRight additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 110, 0); self.layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.adapter.dataSource = self.dataSource; @@ -851,9 +851,9 @@ - (void)test_whenScrollToItem_thatSupplementarySourceSupportsSingleHeader { [self.adapter performUpdatesAnimated:NO completion:nil]; XCTAssertNotNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]); - [self.adapter scrollToObject:@1 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@2 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@2 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; // Content height smaller than collection view height, won't scroll IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); } @@ -874,9 +874,9 @@ - (void)test_whenScrollToItem_thatSupplementarySourceSupportsHeaderAndFooter { XCTAssertNotNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]); XCTAssertNotNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]); - [self.adapter scrollToObject:@1 supplementaryKinds:@[UICollectionElementKindSectionHeader, UICollectionElementKindSectionFooter] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:@[UICollectionElementKindSectionHeader, UICollectionElementKindSectionFooter] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@2 supplementaryKinds:@[UICollectionElementKindSectionHeader, UICollectionElementKindSectionFooter] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@2 supplementaryKinds:@[UICollectionElementKindSectionHeader, UICollectionElementKindSectionFooter] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; // Content height smaller than collection view height, won't scroll IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); } @@ -885,7 +885,7 @@ - (void)test_whenScrollVerticallyToItem_thatFeedIsEmpty { self.dataSource.objects = @[]; [self.adapter reloadDataWithCompletion:nil]; XCTAssertEqual([self.collectionView numberOfSections], 0); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); } @@ -894,14 +894,14 @@ - (void)test_whenScrollVerticallyToItem_thatItemNotInFeed { self.dataSource.objects = @[@1, @2, @3, @4]; [self.adapter reloadDataWithCompletion:nil]; XCTAssertEqual([self.collectionView numberOfSections], 4); - [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@5 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@5 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@2 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@2 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; // Content height is smaller than collection view height, can't scroll IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); - [self.adapter scrollToObject:@5 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self.adapter scrollToObject:@5 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone additionalOffset:0 animated:NO]; // Content height is smaller than collection view height, can't scroll IGAssertEqualPoint([self.collectionView contentOffset], 0, 0); } @@ -914,7 +914,7 @@ - (void)test_whenScrollToItem_thatNonVisibleCellsDidNotAppear { // # of items for each object == [item integerValue], so @2 has 2 items (cells) // Assumptions: UICollectionView size is (100,100), each cell size is (100,10) - [self.adapter scrollToObject:@22 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop animated:NO]; + [self.adapter scrollToObject:@22 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop additionalOffset:0 animated:NO]; // Force the layout, which creates the cells [self.collectionView layoutIfNeeded];