Skip to content

Commit

Permalink
Scroll to focused media below header
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Anna Tang authored and facebook-github-bot committed Aug 11, 2021
1 parent 936f558 commit f2166c3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 47 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *)supplementaryKinds
scrollDirection:(UICollectionViewScrollDirection)scrollDirection
scrollPosition:(UICollectionViewScrollPosition)scrollPosition
animated:(BOOL)animated;

// NEW
- (void)scrollToObject:(id)object
supplementaryKinds:(nullable NSArray<NSString *> *)supplementaryKinds
scrollDirection:(UICollectionViewScrollDirection)scrollDirection
scrollPosition:(UICollectionViewScrollPosition)scrollPosition
additionalOffset:(CGPoint)additionalOffset
animated:(BOOL)animated;
```

### Enhancements

- Added `shouldSelectItemAtIndex:` to `IGListSectionController` . [dirtmelon](https://github.com/dirtmelon)
Expand Down
8 changes: 7 additions & 1 deletion Source/IGListKit/IGListAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *)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;
Expand Down
3 changes: 3 additions & 0 deletions Source/IGListKit/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ - (void)scrollToObject:(id)object
supplementaryKinds:(NSArray<NSString *> *)supplementaryKinds
scrollDirection:(UICollectionViewScrollDirection)scrollDirection
scrollPosition:(UICollectionViewScrollPosition)scrollPosition
additionalOffset:(CGFloat)additionalOffset
animated:(BOOL)animated {
IGAssertMainThread();
IGParameterAssert(object != nil);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit f2166c3

Please sign in to comment.