Customized animation unit test

Summary: test when the item is inserted/removed, if the layout could successfully get the initial/final attributes from the section controller

Reviewed By: rnystrom

Differential Revision: D6759201

fbshipit-source-id: e674662d1e47c374d38019c988c1a37fece2417a
This commit is contained in:
Sue Suhan Ma 2018-01-29 12:31:19 -08:00 committed by Facebook Github Bot
parent 26924ec3b6
commit a18bd7c495
3 changed files with 51 additions and 1 deletions

View file

@ -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

View file

@ -13,7 +13,7 @@
@class IGTestObject;
@interface IGTestDelegateController : IGListSectionController <IGListDisplayDelegate, IGListWorkingRangeDelegate>
@interface IGTestDelegateController : IGListSectionController <IGListDisplayDelegate, IGListWorkingRangeDelegate, IGListTransitionDelegate>
@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

View file

@ -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