Skip to content

Commit

Permalink
Merge pull request TextureGroup#2 from TextureGroup/master
Browse files Browse the repository at this point in the history
updating fork
  • Loading branch information
shanereid authored Aug 15, 2017
2 parents d3aea5a + afeb25a commit 9b3c7aa
Show file tree
Hide file tree
Showing 27 changed files with 237 additions and 114 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
- 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)
- Rename ASCellNode.viewModel to ASCellNode.nodeViewModel to reduce collisions with subclass properties implemented by clients. [Adlai Holler](https://github.com/Adlai-Holler) [#499](https://github.com/TextureGroup/Texture/pull/499)
- Rename ASCellNode.viewModel to ASCellNode.nodeModel to reduce collisions with subclass properties implemented by clients. [Adlai Holler](https://github.com/Adlai-Holler) [#504](https://github.com/TextureGroup/Texture/pull/504)
- [Breaking] 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)

##2.3.5
- Fix an issue where inserting/deleting sections could lead to inconsistent supplementary element behavior. [Adlai Holler](https://github.com/Adlai-Holler)
Expand Down
6 changes: 3 additions & 3 deletions Source/ASCellNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
*
* This property may be set off the main thread, but this method will never be invoked concurrently on the
*/
@property (atomic, nullable) id nodeViewModel;
@property (atomic, nullable) id nodeModel;

/**
* Asks the node whether it can be updated to the given view model.
* Asks the node whether it can be updated to the given node model.
*
* The default implementation returns YES if the class matches that of the current view-model.
*/
- (BOOL)canUpdateToViewModel:(id)viewModel;
- (BOOL)canUpdateToNodeModel:(id)nodeModel;

/**
* The backing view controller, or @c nil if the node wasn't initialized with backing view controller
Expand Down
4 changes: 2 additions & 2 deletions Source/ASCellNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ - (void)__setHighlightedFromUIKit:(BOOL)highlighted;
}
}

- (BOOL)canUpdateToViewModel:(id)viewModel
- (BOOL)canUpdateToNodeModel:(id)nodeModel
{
return [self.nodeViewModel class] == [viewModel class];
return [self.nodeModel class] == [nodeModel class];
}

- (NSIndexPath *)indexPath
Expand Down
22 changes: 18 additions & 4 deletions Source/ASCollectionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, weak) id<ASCollectionViewLayoutInspecting> layoutInspector;

/**
* The offset of the content view's origin from the collection node's origin. Defaults to CGPointZero.
*/
@property (nonatomic, assign) CGPoint contentOffset;

/**
* Sets the offset from the content node’s origin to the collection node’s origin.
*
* @param contentOffset The offset
*
* @param animated YES to animate to this new offset at a constant velocity, NO to not aniamte and immediately make the transition.
*/
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;

/**
* Tuning parameters for a range type in full mode.
*
Expand Down Expand Up @@ -419,15 +433,15 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable __kindof ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;

/**
* Retrieves the view-model for the item at the given index path, if any.
* Retrieves the node-model for the item at the given index path, if any.
*
* @param indexPath The index path of the requested item.
*
* @return The view-model for the given item, or @c nil if no item exists at the specified path or no view-model was provided.
* @return The node-model for the given item, or @c nil if no item exists at the specified path or no node-model was provided.
*
* @warning This API is beta and subject to change. We'll try to provide an easy migration path.
*/
- (nullable id)viewModelForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
- (nullable id)nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;

/**
* Retrieve the index path for the item with the given node.
Expand Down Expand Up @@ -523,7 +537,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An object that contains all the data for this item.
*/
- (nullable id)collectionNode:(ASCollectionNode *)collectionNode viewModelForItemAtIndexPath:(NSIndexPath *)indexPath;
- (nullable id)collectionNode:(ASCollectionNode *)collectionNode nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath;

/**
* Similar to -collectionNode:nodeForItemAtIndexPath:
Expand Down
34 changes: 32 additions & 2 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ @interface _ASCollectionPendingState : NSObject
@property (nonatomic, assign) BOOL usesSynchronousDataLoading;
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
@property (weak, nonatomic) id <ASCollectionViewLayoutInspecting> layoutInspector;
@property (nonatomic, assign) CGPoint contentOffset;
@property (nonatomic, assign) BOOL animatesContentOffset;
@end

@implementation _ASCollectionPendingState
Expand All @@ -61,6 +63,8 @@ - (instancetype)init
_allowsSelection = YES;
_allowsMultipleSelection = NO;
_inverted = NO;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
}
return self;
}
Expand Down Expand Up @@ -189,6 +193,8 @@ - (void)didLoad
if (pendingState.rangeMode != ASLayoutRangeModeUnspecified) {
[view.rangeController updateCurrentRangeWithMode:pendingState.rangeMode];
}

[view setContentOffset:pendingState.contentOffset animated:pendingState.animatesContentOffset];

// Don't need to set collectionViewLayout to the view as the layout was already used to init the view in view block.
}
Expand Down Expand Up @@ -434,6 +440,30 @@ - (UICollectionViewLayout *)collectionViewLayout
}
}

- (void)setContentOffset:(CGPoint)contentOffset
{
[self setContentOffset:contentOffset animated:NO];
}

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
if ([self pendingState]) {
_pendingState.contentOffset = contentOffset;
_pendingState.animatesContentOffset = animated;
} else {
[self.view setContentOffset:contentOffset animated:animated];
}
}

- (CGPoint)contentOffset
{
if ([self pendingState]) {
return _pendingState.contentOffset;
} else {
return self.view.contentOffset;
}
}

- (ASScrollDirection)scrollDirection
{
return [self isNodeLoaded] ? self.view.scrollDirection : ASScrollDirectionNone;
Expand Down Expand Up @@ -594,10 +624,10 @@ - (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].node;
}

- (id)viewModelForItemAtIndexPath:(NSIndexPath *)indexPath
- (id)nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath
{
[self reloadDataInitiallyIfNeeded];
return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].viewModel;
return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].nodeModel;
}

- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode
Expand Down
7 changes: 7 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 point at which the origin of the content view is offset from the origin of the collection view.
*/
@property (nonatomic, assign) CGPoint contentOffset ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode property instead.");

/**
* The object that acts as the asynchronous delegate of the collection view
*
Expand Down Expand Up @@ -407,6 +412,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (NSArray<__kindof ASCellNode *> *)visibleNodes AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode method instead.");

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode method instead.");

@end

ASDISPLAYNODE_DEPRECATED_MSG("Renamed to ASCollectionDataSource.")
Expand Down
10 changes: 5 additions & 5 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
unsigned int collectionViewNumberOfItemsInSection:1;
unsigned int collectionNodeNodeForItem:1;
unsigned int collectionNodeNodeBlockForItem:1;
unsigned int viewModelForItem:1;
unsigned int nodeModelForItem:1;
unsigned int collectionNodeNodeForSupplementaryElement:1;
unsigned int collectionNodeNodeBlockForSupplementaryElement:1;
unsigned int collectionNodeSupplementaryElementKindsInSection:1;
Expand Down Expand Up @@ -431,7 +431,7 @@ - (void)setAsyncDataSource:(id<ASCollectionDataSource>)asyncDataSource
_asyncDataSourceFlags.collectionNodeNodeForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeForSupplementaryElementOfKind:atIndexPath:)];
_asyncDataSourceFlags.collectionNodeNodeBlockForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeBlockForSupplementaryElementOfKind:atIndexPath:)];
_asyncDataSourceFlags.collectionNodeSupplementaryElementKindsInSection = [_asyncDataSource respondsToSelector:@selector(collectionNode:supplementaryElementKindsInSection:)];
_asyncDataSourceFlags.viewModelForItem = [_asyncDataSource respondsToSelector:@selector(collectionNode:viewModelForItemAtIndexPath:)];
_asyncDataSourceFlags.nodeModelForItem = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeModelForItemAtIndexPath:)];

_asyncDataSourceFlags.interop = [_asyncDataSource conformsToProtocol:@protocol(ASCollectionDataSourceInterop)];
if (_asyncDataSourceFlags.interop) {
Expand Down Expand Up @@ -1662,14 +1662,14 @@ - (void)_beginBatchFetching

#pragma mark - ASDataControllerSource

- (id)dataController:(ASDataController *)dataController viewModelForItemAtIndexPath:(NSIndexPath *)indexPath
- (id)dataController:(ASDataController *)dataController nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (!_asyncDataSourceFlags.viewModelForItem) {
if (!_asyncDataSourceFlags.nodeModelForItem) {
return nil;
}

GET_COLLECTIONNODE_OR_RETURN(collectionNode, nil);
return [_asyncDataSource collectionNode:collectionNode viewModelForItemAtIndexPath:indexPath];
return [_asyncDataSource collectionNode:collectionNode nodeModelForItemAtIndexPath:indexPath];
}

- (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAtIndexPath:(NSIndexPath *)indexPath
Expand Down
14 changes: 14 additions & 0 deletions Source/ASTableNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign) BOOL inverted;

/**
* The offset of the content view's origin from the table node's origin. Defaults to CGPointZero.
*/
@property (nonatomic, assign) CGPoint contentOffset;

/**
* Sets the offset from the content node’s origin to the table node’s origin.
*
* @param contentOffset The offset
*
* @param animated YES to animate to this new offset at a constant velocity, NO to not aniamte and immediately make the transition.
*/
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;

/**
* YES to automatically adjust the contentOffset when cells are inserted or deleted above
* visible cells, maintaining the users' visible scroll position.
Expand Down
32 changes: 32 additions & 0 deletions Source/ASTableNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ @interface _ASTablePendingState : NSObject
@property (nonatomic, assign) BOOL allowsMultipleSelectionDuringEditing;
@property (nonatomic, assign) BOOL inverted;
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
@property (nonatomic, assign) CGPoint contentOffset;
@property (nonatomic, assign) BOOL animatesContentOffset;
@property (nonatomic, assign) BOOL automaticallyAdjustsContentOffset;
@end

Expand All @@ -58,6 +60,8 @@ - (instancetype)init
_allowsMultipleSelectionDuringEditing = NO;
_inverted = NO;
_leadingScreensForBatching = 2;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
_automaticallyAdjustsContentOffset = NO;
}
return self;
Expand Down Expand Up @@ -120,6 +124,7 @@ - (void)didLoad
if (pendingState.rangeMode != ASLayoutRangeModeUnspecified) {
[view.rangeController updateCurrentRangeWithMode:pendingState.rangeMode];
}
[view setContentOffset:pendingState.contentOffset animated:pendingState.animatesContentOffset];
}
}

Expand Down Expand Up @@ -232,6 +237,33 @@ - (CGFloat)leadingScreensForBatching
}
}

- (void)setContentOffset:(CGPoint)contentOffset
{
[self setContentOffset:contentOffset animated:NO];
}

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
_ASTablePendingState *pendingState = self.pendingState;
if (pendingState) {
pendingState.contentOffset = contentOffset;
pendingState.animatesContentOffset = animated;
} else {
ASDisplayNodeAssert(self.nodeLoaded, @"ASTableNode should be loaded if pendingState doesn't exist");
[self.view setContentOffset:contentOffset animated:animated];
}
}

- (CGPoint)contentOffset
{
_ASTablePendingState *pendingState = self.pendingState;
if (pendingState) {
return pendingState.contentOffset;
} else {
return self.view.contentOffset;
}
}

- (void)setAutomaticallyAdjustsContentOffset:(BOOL)automaticallyAdjustsContentOffset
{
_ASTablePendingState *pendingState = self.pendingState;
Expand Down
18 changes: 12 additions & 6 deletions Source/ASTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

/**
* The offset of the content view's origin from the table node's origin. Defaults to CGPointZero.
*/
@property (nonatomic, assign) CGPoint contentOffset ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

/**
* YES to automatically adjust the contentOffset when cells are inserted or deleted above
Expand All @@ -84,6 +88,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign) BOOL inverted ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

@property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

@property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForSelectedRows ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

@property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForVisibleRows ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

/**
* Tuning parameters for a range type in full mode.
*
Expand Down Expand Up @@ -138,12 +148,6 @@ NS_ASSUME_NONNULL_BEGIN

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");

@property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

@property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForSelectedRows ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

@property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForVisibleRows ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");

- (nullable NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");

- (nullable NSArray<NSIndexPath *> *)indexPathsForRowsInRect:(CGRect)rect ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
Expand Down Expand Up @@ -241,6 +245,8 @@ NS_ASSUME_NONNULL_BEGIN
/// Deprecated in 2.0. You should not call this method.
- (void)clearFetchedData ASDISPLAYNODE_DEPRECATED_MSG("You should not call this method directly. Intead, rely on the Interstate State callback methods.");

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");

@end

ASDISPLAYNODE_DEPRECATED_MSG("Renamed to ASTableDataSource.")
Expand Down
2 changes: 1 addition & 1 deletion Source/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ - (void)rangeController:(ASRangeController *)rangeController updateWithChangeSet

#pragma mark - ASDataControllerSource

- (id)dataController:(ASDataController *)dataController viewModelForItemAtIndexPath:(NSIndexPath *)indexPath
- (id)dataController:(ASDataController *)dataController nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Not currently supported for tables. Will be added when the collection API stabilizes.
return nil;
Expand Down
4 changes: 2 additions & 2 deletions Source/Details/ASCollectionElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ AS_SUBCLASSING_RESTRICTED
@property (nonatomic, assign) ASSizeRange constrainedSize;
@property (nonatomic, readonly, weak) id<ASRangeManagingNode> owningNode;
@property (nonatomic, assign) ASPrimitiveTraitCollection traitCollection;
@property (nonatomic, readonly, nullable) id viewModel;
@property (nonatomic, readonly, nullable) id nodeModel;

- (instancetype)initWithViewModel:(nullable id)viewModel
- (instancetype)initWithNodeModel:(nullable id)nodeModel
nodeBlock:(ASCellNodeBlock)nodeBlock
supplementaryElementKind:(nullable NSString *)supplementaryElementKind
constrainedSize:(ASSizeRange)constrainedSize
Expand Down
6 changes: 3 additions & 3 deletions Source/Details/ASCollectionElement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @implementation ASCollectionElement {
ASCellNode *_node;
}

- (instancetype)initWithViewModel:(id)viewModel
- (instancetype)initWithNodeModel:(id)nodeModel
nodeBlock:(ASCellNodeBlock)nodeBlock
supplementaryElementKind:(NSString *)supplementaryElementKind
constrainedSize:(ASSizeRange)constrainedSize
Expand All @@ -41,7 +41,7 @@ - (instancetype)initWithViewModel:(id)viewModel
NSAssert(nodeBlock != nil, @"Node block must not be nil");
self = [super init];
if (self) {
_viewModel = viewModel;
_nodeModel = nodeModel;
_nodeBlock = nodeBlock;
_supplementaryElementKind = [supplementaryElementKind copy];
_constrainedSize = constrainedSize;
Expand All @@ -64,7 +64,7 @@ - (ASCellNode *)node
node.owningNode = _owningNode;
node.collectionElement = self;
ASTraitCollectionPropagateDown(node, _traitCollection);
node.nodeViewModel = _viewModel;
node.nodeModel = _nodeModel;
_node = node;
}
return _node;
Expand Down
1 change: 1 addition & 0 deletions Source/Details/ASCollectionLayoutContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ AS_SUBCLASSING_RESTRICTED
@interface ASCollectionLayoutContext : NSObject

@property (nonatomic, assign, readonly) CGSize viewportSize;
@property (nonatomic, assign, readonly) CGPoint initialContentOffset;
@property (nonatomic, assign, readonly) ASScrollDirection scrollableDirections;
@property (nonatomic, weak, readonly) ASElementMap *elements;
@property (nonatomic, strong, readonly, nullable) id additionalInfo;
Expand Down
Loading

0 comments on commit 9b3c7aa

Please sign in to comment.