From a4bae434717594e570cf115c7f06b9456471abfc Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Mon, 13 Nov 2023 09:50:13 -0800 Subject: [PATCH] Refine and add code coverage for trait collection in collection context Summary: Now that the inconsistency exception is being wrapped up, I'm going to move forward with a public release some more. I'm going to go through and make sure everything is up-to-date in the GitHub repo. This diff adds code coverage to the new trait collection exposure API in `IGListCollectionContext`. It also adds document-generating compatible commenting and positions it at a more appropriate ordering in the header. Reviewed By: zats Differential Revision: D51146049 fbshipit-source-id: 2d7ecc8fa042006ef4fd70451b9ab7ba6d0a66bb --- Source/IGListKit/IGListAdapter.m | 2 +- Source/IGListKit/IGListCollectionContext.h | 7 +++++-- Tests/IGListAdapterTests.m | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/IGListKit/IGListAdapter.m b/Source/IGListKit/IGListAdapter.m index b32d8d574..72db9d0d4 100644 --- a/Source/IGListKit/IGListAdapter.m +++ b/Source/IGListKit/IGListAdapter.m @@ -978,7 +978,7 @@ - (CGSize)containerSize { return self.collectionView.bounds.size; } -- (UITraitCollection *_Nullable)traitCollection { +- (UITraitCollection *)traitCollection { return self.collectionView.traitCollection; } diff --git a/Source/IGListKit/IGListCollectionContext.h b/Source/IGListKit/IGListCollectionContext.h index 86569768b..6f0a550c2 100644 --- a/Source/IGListKit/IGListCollectionContext.h +++ b/Source/IGListKit/IGListCollectionContext.h @@ -26,8 +26,6 @@ NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(ListCollectionContext) @protocol IGListCollectionContext -@property (nonatomic, nullable, readonly) UITraitCollection *traitCollection; - /** The size of the collection view. You can use this for sizing cells. */ @@ -53,6 +51,11 @@ NS_SWIFT_NAME(ListCollectionContext) */ @property (nonatomic, readonly) CGPoint containerContentOffset; +/** + The trait collection of the collection view. + */ +@property (nonatomic, nullable, readonly) UITraitCollection *traitCollection; + /** The current scrolling traits of the underlying collection view. */ diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index a08253d07..7ee8bdd45 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -1736,6 +1736,12 @@ - (void)test_whenSupplementarySourceReturnsNegativeSize_thatAdapterReturnsZero { XCTAssertEqual(size.height, 0.0); } +- (void)test_whenQueryingTraitCollection_thatMatchesCollectionView { + self.dataSource.objects = @[@2]; + [self.adapter reloadDataWithCompletion:nil]; + XCTAssertEqual(self.adapter.traitCollection, self.collectionView.traitCollection); +} + - (void)test_whenQueryingContainerInset_thatMatchesCollectionView { self.dataSource.objects = @[@2]; [self.adapter reloadDataWithCompletion:nil];