Fix calculation of vertical and horizontal center in scrollToObject

Summary: Fix bug where scroll position would be incorrect in call to `-[IGListAdapter scrollToObject:supplementaryKinds:scrollDirection:scrollPosition:animated:` with scrollDirection/scrollPosition of UICollectionViewScrollDirectionVertical/UICollectionViewScrollPositionCenteredVertically or UICollectionViewScrollDirectionHorizontal/UICollectionViewScrollPositionCenteredHorizontally and with a collection view with nonzero contentInset.

Reviewed By: jessesquires

Differential Revision: D4475043

fbshipit-source-id: 4714ab0ed02e52e2d7f333624cc17858058ee57f
This commit is contained in:
David Yamnitsky 2017-02-01 12:11:40 -08:00 committed by Facebook Github Bot
parent 24d74adf04
commit 5cc0fcd1d7
2 changed files with 10 additions and 4 deletions

View file

@ -41,6 +41,8 @@ This release closes the [2.2.0 milestone](https://github.com/Instagram/IGListKit
- Fix potential bug with suppressing animations (by passing `NO`) during `-[IGListAdapter performUpdatesAnimated: completion:]` where user would see UI glitches/flashing. [Jesse Squires](https://github.com/jessesquires) [(tbd)]()
- Fix bug where scroll position would be incorrect in call to `-[IGListAdapter scrollToObject:supplementaryKinds:scrollDirection:scrollPosition:animated:` with scrollDirection/scrollPosition of UICollectionViewScrollDirectionVertical/UICollectionViewScrollPositionCenteredVertically or UICollectionViewScrollDirectionHorizontal/UICollectionViewScrollPositionCenteredHorizontally and with a collection view with nonzero contentInset. [David Yamnitsky](https://github.com/nitsky)
2.1.0
-----

View file

@ -206,9 +206,11 @@
case UICollectionViewScrollPositionRight:
contentOffset.x = offsetMax - collectionViewWidth - contentInset.left;
break;
case UICollectionViewScrollPositionCenteredHorizontally:
contentOffset.x = offsetMid - collectionViewWidth / 2.0 - contentInset.left;
case UICollectionViewScrollPositionCenteredHorizontally: {
const CGFloat insets = (contentInset.left - contentInset.right) / 2.0;
contentOffset.x = offsetMid - collectionViewWidth / 2.0 - insets;
break;
}
case UICollectionViewScrollPositionLeft:
case UICollectionViewScrollPositionNone:
case UICollectionViewScrollPositionTop:
@ -223,9 +225,11 @@
case UICollectionViewScrollPositionBottom:
contentOffset.y = offsetMax - collectionViewHeight - contentInset.top;
break;
case UICollectionViewScrollPositionCenteredVertically:
contentOffset.y = offsetMid - collectionViewHeight / 2.0 - contentInset.top;
case UICollectionViewScrollPositionCenteredVertically: {
const CGFloat insets = (contentInset.top - contentInset.bottom) / 2.0;
contentOffset.y = offsetMid - collectionViewHeight / 2.0 - insets;
break;
}
case UICollectionViewScrollPositionTop:
case UICollectionViewScrollPositionNone:
case UICollectionViewScrollPositionLeft: