From b282fb8fb152e63e599b3a0b6461dae0699ffdcb Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 11 Sep 2017 12:58:34 +0100 Subject: [PATCH 1/4] Add content inset bridging property to table and collection nodes --- CHANGELOG.md | 2 +- Source/ASCollectionNode.h | 5 +++ Source/ASCollectionNode.mm | 23 +++++++++++ Source/ASCollectionView.h | 5 +++ Source/ASTableNode.h | 5 +++ Source/ASTableNode.mm | 40 +++++++++++++++---- Source/ASTableView.h | 5 +++ .../Private/ASCollectionView+Undeprecated.h | 2 + Source/Private/ASTableView+Undeprecated.h | 1 + 9 files changed, 80 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b69fcd8f..99a816383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - Add -[ASDisplayNode detailedLayoutDescription] property to aid debugging. [Adlai Holler](https://github.com/Adlai-Holler) [#476](https://github.com/TextureGroup/Texture/pull/476) - Fix an issue that causes calculatedLayoutDidChange being called needlessly. [Huy Nguyen](https://github.com/nguyenhuy) [#490](https://github.com/TextureGroup/Texture/pull/490) - Negate iOS 11 automatic estimated table row heights. [Christian Selig](https://github.com/christianselig) [#485](https://github.com/TextureGroup/Texture/pull/485) -- Add content offset bridging property to ASTableNode and ASCollectionNode. Deprecate related methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) +- Add content inset and offset bridging properties to ASTableNode and ASCollectionNode. Deprecate related properties and methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) [#559](https://github.com/TextureGroup/Texture/pull/559) - Remove re-entrant access to self.view when applying initial pending state. [Adlai Holler](https://github.com/Adlai-Holler) [#510](https://github.com/TextureGroup/Texture/pull/510) - Small improvements in ASCollectionLayout [Huy Nguyen](https://github.com/nguyenhuy) [#509](https://github.com/TextureGroup/Texture/pull/509) [#513](https://github.com/TextureGroup/Texture/pull/513) - Fix retain cycle between ASImageNode and PINAnimatedImage [Phil Larson](https://github.com/plarson) [#520](https://github.com/TextureGroup/Texture/pull/520) diff --git a/Source/ASCollectionNode.h b/Source/ASCollectionNode.h index 68e5d752f..6913f8720 100644 --- a/Source/ASCollectionNode.h +++ b/Source/ASCollectionNode.h @@ -128,6 +128,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, weak) id layoutInspector; +/** + * The distance that the content view is inset from the collection node edges. Defaults to UIEdgeInsetsZero. + */ +@property (nonatomic, assign) UIEdgeInsets contentInset; + /** * The offset of the content view's origin from the collection node's origin. Defaults to CGPointZero. */ diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index e5cde4c8e..473ed4e34 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -49,6 +49,7 @@ @interface _ASCollectionPendingState : NSObject @property (nonatomic, assign) BOOL usesSynchronousDataLoading; @property (nonatomic, assign) CGFloat leadingScreensForBatching; @property (weak, nonatomic) id layoutInspector; +@property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) CGPoint contentOffset; @property (nonatomic, assign) BOOL animatesContentOffset; @end @@ -63,6 +64,7 @@ - (instancetype)init _allowsSelection = YES; _allowsMultipleSelection = NO; _inverted = NO; + _contentInsets = UIEdgeInsetsZero; _contentOffset = CGPointZero; _animatesContentOffset = NO; } @@ -188,6 +190,7 @@ - (void)didLoad view.allowsMultipleSelection = pendingState.allowsMultipleSelection; view.usesSynchronousDataLoading = pendingState.usesSynchronousDataLoading; view.layoutInspector = pendingState.layoutInspector; + view.contentInset = pendingState.contentInset; self.pendingState = nil; if (pendingState.rangeMode != ASLayoutRangeModeUnspecified) { @@ -440,6 +443,25 @@ - (UICollectionViewLayout *)collectionViewLayout } } +- (void)setContentInset:(UIEdgeInsets)contentInset +{ + if ([self pendingState]) { + _pendingState.contentInset = contentInset; + } else { + ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist"); + self.view.contentInset = contentInset; + } +} + +- (UIEdgeInsets)contentInset +{ + if ([self pendingState]) { + return _pendingState.contentInset; + } else { + return self.view.contentInset; + } +} + - (void)setContentOffset:(CGPoint)contentOffset { [self setContentOffset:contentOffset animated:NO]; @@ -451,6 +473,7 @@ - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated _pendingState.contentOffset = contentOffset; _pendingState.animatesContentOffset = animated; } else { + ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist"); [self.view setContentOffset:contentOffset animated:animated]; } } diff --git a/Source/ASCollectionView.h b/Source/ASCollectionView.h index 2c1f87984..ba9dda296 100644 --- a/Source/ASCollectionView.h +++ b/Source/ASCollectionView.h @@ -141,6 +141,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic) BOOL zeroContentInsets ASDISPLAYNODE_DEPRECATED_MSG("Set automaticallyAdjustsScrollViewInsets=NO on your view controller instead."); +/** + * The distance that the content view is inset from the collection view edges. Defaults to UIEdgeInsetsZero. + */ +@property (nonatomic, assign) UIEdgeInsets contentInset ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode property instead"); + /** * The point at which the origin of the content view is offset from the origin of the collection view. */ diff --git a/Source/ASTableNode.h b/Source/ASTableNode.h index 08b26a6fd..8322faaf4 100644 --- a/Source/ASTableNode.h +++ b/Source/ASTableNode.h @@ -55,6 +55,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) BOOL inverted; +/** + * The distance that the content view is inset from the table node edges. Defaults to UIEdgeInsetsZero. + */ +@property (nonatomic, assign) UIEdgeInsets contentInset; + /** * The offset of the content view's origin from the table node's origin. Defaults to CGPointZero. */ diff --git a/Source/ASTableNode.mm b/Source/ASTableNode.mm index b4a3e06db..d68e4a9d7 100644 --- a/Source/ASTableNode.mm +++ b/Source/ASTableNode.mm @@ -43,6 +43,7 @@ @interface _ASTablePendingState : NSObject @property (nonatomic, assign) BOOL allowsMultipleSelectionDuringEditing; @property (nonatomic, assign) BOOL inverted; @property (nonatomic, assign) CGFloat leadingScreensForBatching; +@property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) CGPoint contentOffset; @property (nonatomic, assign) BOOL animatesContentOffset; @property (nonatomic, assign) BOOL automaticallyAdjustsContentOffset; @@ -60,6 +61,7 @@ - (instancetype)init _allowsMultipleSelectionDuringEditing = NO; _inverted = NO; _leadingScreensForBatching = 2; + _contentInset = UIEdgeInsetsZero; _contentOffset = CGPointZero; _animatesContentOffset = NO; _automaticallyAdjustsContentOffset = NO; @@ -113,17 +115,20 @@ - (void)didLoad if (_pendingState) { _ASTablePendingState *pendingState = _pendingState; - self.pendingState = nil; - view.asyncDelegate = pendingState.delegate; - view.asyncDataSource = pendingState.dataSource; - view.inverted = pendingState.inverted; - view.allowsSelection = pendingState.allowsSelection; - view.allowsSelectionDuringEditing = pendingState.allowsSelectionDuringEditing; - view.allowsMultipleSelection = pendingState.allowsMultipleSelection; + view.asyncDelegate = pendingState.delegate; + view.asyncDataSource = pendingState.dataSource; + view.inverted = pendingState.inverted; + view.allowsSelection = pendingState.allowsSelection; + view.allowsSelectionDuringEditing = pendingState.allowsSelectionDuringEditing; + view.allowsMultipleSelection = pendingState.allowsMultipleSelection; view.allowsMultipleSelectionDuringEditing = pendingState.allowsMultipleSelectionDuringEditing; + view.contentInset = pendingState.contentInset; + self.pendingState = nil; + if (pendingState.rangeMode != ASLayoutRangeModeUnspecified) { [view.rangeController updateCurrentRangeWithMode:pendingState.rangeMode]; } + [view setContentOffset:pendingState.contentOffset animated:pendingState.animatesContentOffset]; } } @@ -237,6 +242,27 @@ - (CGFloat)leadingScreensForBatching } } +- (void)setContentInset:(UIEdgeInsets)contentInset +{ + _ASTablePendingState *pendingState = self.pendingState; + if (pendingState) { + pendingState.contentInset = contentInset; + } else { + ASDisplayNodeAssert(self.nodeLoaded, @"ASTableNode should be loaded if pendingState doesn't exist"); + self.view.contentInset = contentInset; + } +} + +- (UIEdgeInsets)contentInset +{ + _ASTablePendingState *pendingState = self.pendingState; + if (pendingState) { + return pendingState.contentInset; + } else { + return self.view.contentInset; + } +} + - (void)setContentOffset:(CGPoint)contentOffset { [self setContentOffset:contentOffset animated:NO]; diff --git a/Source/ASTableView.h b/Source/ASTableView.h index 04e1dbd12..ba6736eba 100644 --- a/Source/ASTableView.h +++ b/Source/ASTableView.h @@ -67,6 +67,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) CGFloat leadingScreensForBatching ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead."); +/** + * The distance that the content view is inset from the table view edges. Defaults to UIEdgeInsetsZero. + */ +@property (nonatomic, assign) UIEdgeInsets contentInset ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead"); + /** * The offset of the content view's origin from the table node's origin. Defaults to CGPointZero. */ diff --git a/Source/Private/ASCollectionView+Undeprecated.h b/Source/Private/ASCollectionView+Undeprecated.h index 811ba7baf..591f49efa 100644 --- a/Source/Private/ASCollectionView+Undeprecated.h +++ b/Source/Private/ASCollectionView+Undeprecated.h @@ -75,6 +75,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) id layoutInspector; +@property (nonatomic, assign) UIEdgeInsets contentInset; + @property (nonatomic, assign) CGPoint contentOffset; /** diff --git a/Source/Private/ASTableView+Undeprecated.h b/Source/Private/ASTableView+Undeprecated.h index bef11339d..bab43adf0 100644 --- a/Source/Private/ASTableView+Undeprecated.h +++ b/Source/Private/ASTableView+Undeprecated.h @@ -33,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) id asyncDelegate; @property (nonatomic, weak) id asyncDataSource; +@property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) CGPoint contentOffset; @property (nonatomic, assign) BOOL automaticallyAdjustsContentOffset; @property (nonatomic, assign) BOOL inverted; From 08cbb3152f3b177072cf0f965b18422d4ab87b11 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 11 Sep 2017 13:00:48 +0100 Subject: [PATCH 2/4] Fix CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a816383..0ed354b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - Add -[ASDisplayNode detailedLayoutDescription] property to aid debugging. [Adlai Holler](https://github.com/Adlai-Holler) [#476](https://github.com/TextureGroup/Texture/pull/476) - Fix an issue that causes calculatedLayoutDidChange being called needlessly. [Huy Nguyen](https://github.com/nguyenhuy) [#490](https://github.com/TextureGroup/Texture/pull/490) - Negate iOS 11 automatic estimated table row heights. [Christian Selig](https://github.com/christianselig) [#485](https://github.com/TextureGroup/Texture/pull/485) -- Add content inset and offset bridging properties to ASTableNode and ASCollectionNode. Deprecate related properties and methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) [#559](https://github.com/TextureGroup/Texture/pull/559) +- Add content inset and offset bridging properties to ASTableNode and ASCollectionNode. Deprecate related properties and methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) [#560](https://github.com/TextureGroup/Texture/pull/560) - Remove re-entrant access to self.view when applying initial pending state. [Adlai Holler](https://github.com/Adlai-Holler) [#510](https://github.com/TextureGroup/Texture/pull/510) - Small improvements in ASCollectionLayout [Huy Nguyen](https://github.com/nguyenhuy) [#509](https://github.com/TextureGroup/Texture/pull/509) [#513](https://github.com/TextureGroup/Texture/pull/513) - Fix retain cycle between ASImageNode and PINAnimatedImage [Phil Larson](https://github.com/plarson) [#520](https://github.com/TextureGroup/Texture/pull/520) From 7afa32b656e9ed588382e37cbcc86328ff18f0f5 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 11 Sep 2017 13:04:59 +0100 Subject: [PATCH 3/4] Fix typo --- Source/ASCollectionNode.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index 473ed4e34..0be5cda59 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -64,7 +64,7 @@ - (instancetype)init _allowsSelection = YES; _allowsMultipleSelection = NO; _inverted = NO; - _contentInsets = UIEdgeInsetsZero; + _contentInset = UIEdgeInsetsZero; _contentOffset = CGPointZero; _animatesContentOffset = NO; } From 64a9b06020f1f5ea3c2bea1b5fb9be5ce3a55ec5 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 11 Sep 2017 13:09:09 +0100 Subject: [PATCH 4/4] Minor fixes --- Source/ASPagerNode.m | 2 +- Tests/ASPagerNodeTests.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/ASPagerNode.m b/Source/ASPagerNode.m index 4d8195a17..719a45687 100644 --- a/Source/ASPagerNode.m +++ b/Source/ASPagerNode.m @@ -115,7 +115,7 @@ - (NSInteger)currentPageIndex - (CGSize)pageSize { - UIEdgeInsets contentInset = self.view.contentInset; + UIEdgeInsets contentInset = self.contentInset; CGSize pageSize = self.bounds.size; pageSize.height -= (contentInset.top + contentInset.bottom); return pageSize; diff --git a/Tests/ASPagerNodeTests.m b/Tests/ASPagerNodeTests.m index 4b45a8c1e..05396387b 100644 --- a/Tests/ASPagerNodeTests.m +++ b/Tests/ASPagerNodeTests.m @@ -138,7 +138,7 @@ - (void)DISABLED_testThatRootPagerNodeDoesGetTheRightInsetWhilePoppingBack XCTAssertEqualObjects(NSStringFromCGRect(window.bounds), NSStringFromCGRect(node.frame)); XCTAssertEqualObjects(NSStringFromCGRect(window.bounds), NSStringFromCGRect(cell.frame)); XCTAssertEqual(pagerNode.contentOffset.y, 0); - XCTAssertEqual(pagerNode.view.contentInset.top, 0); + XCTAssertEqual(pagerNode.contentInset.top, 0); e = [self expectationWithDescription:@"Transition completed"]; // Push another view controller @@ -168,7 +168,7 @@ - (void)DISABLED_testThatRootPagerNodeDoesGetTheRightInsetWhilePoppingBack XCTAssertEqualObjects(NSStringFromCGRect(window.bounds), NSStringFromCGRect(node.frame)); XCTAssertEqualObjects(NSStringFromCGRect(window.bounds), NSStringFromCGRect(cell.frame)); XCTAssertEqual(pagerNode.contentOffset.y, 0); - XCTAssertEqual(pagerNode.view.contentInset.top, 0); + XCTAssertEqual(pagerNode.contentInset.top, 0); } @end