diff --git a/CHANGELOG.md b/CHANGELOG.md index ecdf13ec0d..bba58ac8c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 6c1e04edfa..3b89646862 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -664,11 +664,13 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; - (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; diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 7074bbcbfa..1894b421f8 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -919,8 +919,14 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (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 /** @@ -1819,6 +1825,9 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; 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];