diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index bb2d0710..ae3227d3 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -20,6 +20,7 @@ #import "IGTestObject.h" #import "IGListTestCase.h" #import "IGListAdapterUpdateTester.h" +#import "IGListTestHelpers.h" @interface IGListAdapterE2ETests : IGListTestCase @end @@ -1805,4 +1806,32 @@ [self waitForExpectationsWithTimeout:30 handler:nil]; } +- (void)test_whenModifyingInitialAndFinalAttribute_thatLayoutIsCorrect { + // set up the custom layout + IGListCollectionViewLayout *layout = [[IGListCollectionViewLayout alloc] initWithStickyHeaders:NO topContentInset:0 stretchToEdge:YES]; + self.collectionView.collectionViewLayout = layout; + + IGTestObject *object = genTestObject(@1, @2); + [self setupWithObjects:@ [object]]; + + // set up the section controller + IGTestDelegateController *sectionController = [self.adapter sectionControllerForObject:object]; + sectionController.transitionDelegate = sectionController; + + CGPoint offset = CGPointMake(10, 10); + NSIndexPath *indexPath = genIndexPath(0, 0); + UICollectionViewLayoutAttributes *attribute = [layout layoutAttributesForItemAtIndexPath:indexPath]; + + // set up the custom initial attribute transformation + sectionController.initialAttributesOffset = offset; + UICollectionViewLayoutAttributes *initialAttribute = [layout initialLayoutAttributesForAppearingItemAtIndexPath:indexPath]; + + // set up the custom final attribute transformation + sectionController.finalAttributesOffset = offset; + UICollectionViewLayoutAttributes *finalAttribute = [layout finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath]; + + IGAssertEqualPoint(initialAttribute.center, attribute.center.x + offset.x, attribute.center.y + offset.y); + IGAssertEqualPoint(finalAttribute.center, attribute.center.x + offset.x ,attribute.center.y + offset.y); +} + @end diff --git a/Tests/Objects/IGTestDelegateController.h b/Tests/Objects/IGTestDelegateController.h index b6459f1a..3eb064e4 100644 --- a/Tests/Objects/IGTestDelegateController.h +++ b/Tests/Objects/IGTestDelegateController.h @@ -13,7 +13,7 @@ @class IGTestObject; -@interface IGTestDelegateController : IGListSectionController +@interface IGTestDelegateController : IGListSectionController @property (nonatomic, strong) IGTestObject *item; @@ -28,4 +28,7 @@ @property (nonatomic, strong) NSCountedSet *willDisplayCellIndexes; @property (nonatomic, strong) NSCountedSet *didEndDisplayCellIndexes; +@property (nonatomic, assign) CGPoint initialAttributesOffset; +@property (nonatomic, assign) CGPoint finalAttributesOffset; + @end diff --git a/Tests/Objects/IGTestDelegateController.m b/Tests/Objects/IGTestDelegateController.m index 5f906d11..e1d99c18 100644 --- a/Tests/Objects/IGTestDelegateController.m +++ b/Tests/Objects/IGTestDelegateController.m @@ -91,4 +91,22 @@ - (void)listAdapter:(IGListAdapter *)listAdapter sectionControllerDidExitWorkingRange:(IGListSectionController *)sectionController {} +#pragma mark - IGListTransitionDelegate + +- (UICollectionViewLayoutAttributes *)listAdapter:(IGListAdapter *)listAdapter + customizedInitialLayoutAttributes:(UICollectionViewLayoutAttributes *)attributes + sectionController:(IGListSectionController *)sectionController + atIndex:(NSInteger)index { + attributes.center = CGPointMake(attributes.center.x + _initialAttributesOffset.x, attributes.center.y + _initialAttributesOffset.y); + return attributes; +} + +- (UICollectionViewLayoutAttributes *)listAdapter:(IGListAdapter *)listAdapter + customizedFinalLayoutAttributes:(UICollectionViewLayoutAttributes *)attributes + sectionController:(IGListSectionController *)sectionController + atIndex:(NSInteger)index { + attributes.center = CGPointMake(attributes.center.x + _finalAttributesOffset.x, attributes.center.y + _finalAttributesOffset.y); + return attributes; +} + @end