Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCollectionNode][ASTableNode] Add content inset bridging property #560

Merged
merged 4 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) [#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)
Expand Down
5 changes: 5 additions & 0 deletions Source/ASCollectionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, weak) id<ASCollectionViewLayoutInspecting> 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.
*/
Expand Down
23 changes: 23 additions & 0 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ @interface _ASCollectionPendingState : NSObject
@property (nonatomic, assign) BOOL usesSynchronousDataLoading;
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
@property (weak, nonatomic) id <ASCollectionViewLayoutInspecting> layoutInspector;
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, assign) CGPoint contentOffset;
@property (nonatomic, assign) BOOL animatesContentOffset;
@end
Expand All @@ -63,6 +64,7 @@ - (instancetype)init
_allowsSelection = YES;
_allowsMultipleSelection = NO;
_inverted = NO;
_contentInset = UIEdgeInsetsZero;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
Expand All @@ -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];
}
}
Expand Down
5 changes: 5 additions & 0 deletions Source/ASCollectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion Source/ASPagerNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Source/ASTableNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
40 changes: 33 additions & 7 deletions Source/ASTableNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,6 +61,7 @@ - (instancetype)init
_allowsMultipleSelectionDuringEditing = NO;
_inverted = NO;
_leadingScreensForBatching = 2;
_contentInset = UIEdgeInsetsZero;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
_automaticallyAdjustsContentOffset = NO;
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions Source/ASTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions Source/Private/ASCollectionView+Undeprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, weak) id<ASCollectionViewLayoutInspecting> layoutInspector;

@property (nonatomic, assign) UIEdgeInsets contentInset;

@property (nonatomic, assign) CGPoint contentOffset;

/**
Expand Down
1 change: 1 addition & 0 deletions Source/Private/ASTableView+Undeprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, weak) id<ASTableDelegate> asyncDelegate;
@property (nonatomic, weak) id<ASTableDataSource> asyncDataSource;
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, assign) CGPoint contentOffset;
@property (nonatomic, assign) BOOL automaticallyAdjustsContentOffset;
@property (nonatomic, assign) BOOL inverted;
Expand Down
4 changes: 2 additions & 2 deletions Tests/ASPagerNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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