Skip to content

Commit

Permalink
[ASTableView] Generate a new cell layout if existing ones are invalid (
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy authored May 28, 2018
1 parent 60e3f97 commit 8a4bb6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- [ASDisplayNode] Fix an issue that causes a node to sometimes return an outdated calculated size or size range. [Huy Nguyen](https://github.com/nguyenhuy) [#808](https://github.com/TextureGroup/Texture/pull/808)
- Add an experimental deallocation queue implementation that's more efficient. [Adlai Holler](https://github.com/Adlai-Holler)
- Standardize property declaration style. [Adlai Holler](https://github.com/Adlai-Holler)
- [ASTableView] Fix an issue that causes table view to use one of a cell's invalid layouts instead of generating a new one. [Huy Nguyen](https://github.com/nguyenhuy) [#942](https://github.com/TextureGroup/Texture/pull/942)

## 2.6
- [Xcode 9] Updated to require Xcode 9 (to fix warnings) [Garrett Moon](https://github.com/garrettmoon)
Expand Down
6 changes: 4 additions & 2 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,13 @@ - (BOOL)zeroContentInsets
- (CGSize)sizeForElement:(ASCollectionElement *)element
{
ASDisplayNodeAssertMainThread();
ASCellNode *node = element.node;
if (element == nil || node == nil) {
if (element == nil) {
return CGSizeZero;
}

ASCellNode *node = element.node;
ASDisplayNodeAssertNotNil(node, @"Node must not be nil!");

BOOL useUIKitCell = node.shouldUseUIKitCell;
if (useUIKitCell) {
ASWrapperCellNode *wrapperNode = (ASWrapperCellNode *)node;
Expand Down
13 changes: 11 additions & 2 deletions Source/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
ASCellNode *node = [_dataController.visibleMap elementForItemAtIndexPath:indexPath].node;
CGFloat height = node.calculatedSize.height;
CGFloat height = 0.0;

ASCollectionElement *element = [_dataController.visibleMap elementForItemAtIndexPath:indexPath];
if (element != nil) {
ASCellNode *node = element.node;
ASDisplayNodeAssertNotNil(node, @"Node must not be nil!");
height = [node layoutThatFits:element.constrainedSize].size.height;
}

#if TARGET_OS_IOS
/**
Expand Down Expand Up @@ -1819,6 +1825,9 @@ - (void)didLayoutSubviewsOfTableViewCell:(_ASTableViewCell *)tableViewCell
const CGSize calculatedSize = [node layoutThatFits:constrainedSize].size;
node.frame = { .size = calculatedSize };

// After the re-measurement, set the new constrained size to the node's backing colleciton element.
node.collectionElement.constrainedSize = constrainedSize;

// If the node height changed, trigger a height requery.
if (oldSize.height != calculatedSize.height) {
[self beginUpdates];
Expand Down

0 comments on commit 8a4bb6c

Please sign in to comment.