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

* Add content inset bridging property to table and collection nodes

* Fix CHANGELOG

* Fix typo

* Minor fixes
This commit is contained in:
Huy Nguyen
2017-09-11 19:20:32 +01:00
committed by GitHub
parent 3c77d4a5da
commit fcee108af5
11 changed files with 83 additions and 11 deletions

View File

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

View File

@@ -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.
*/

View File

@@ -49,6 +49,7 @@
@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
@@ -63,6 +64,7 @@
_allowsSelection = YES;
_allowsMultipleSelection = NO;
_inverted = NO;
_contentInset = UIEdgeInsetsZero;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
}
@@ -188,6 +190,7 @@
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 @@
}
}
- (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 @@
_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];
}
}

View File

@@ -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.
*/

View File

@@ -115,7 +115,7 @@
- (CGSize)pageSize
{
UIEdgeInsets contentInset = self.view.contentInset;
UIEdgeInsets contentInset = self.contentInset;
CGSize pageSize = self.bounds.size;
pageSize.height -= (contentInset.top + contentInset.bottom);
return pageSize;

View File

@@ -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.
*/

View File

@@ -43,6 +43,7 @@
@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 @@
_allowsMultipleSelectionDuringEditing = NO;
_inverted = NO;
_leadingScreensForBatching = 2;
_contentInset = UIEdgeInsetsZero;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
_automaticallyAdjustsContentOffset = NO;
@@ -113,17 +115,20 @@
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 @@
}
}
- (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];

View File

@@ -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.
*/

View File

@@ -75,6 +75,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) id<ASCollectionViewLayoutInspecting> layoutInspector;
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, assign) CGPoint contentOffset;
/**

View File

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

View File

@@ -138,7 +138,7 @@
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 @@
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