From e78485ceea9fe456f6d0467feb53e7b4a0bcf247 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Fri, 25 May 2018 19:46:00 +0300 Subject: [PATCH 1/6] During row height query, ASTableView should generate a new cell layout if the existing ones are invalid --- Source/ASTableView.mm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 273bca46f..59c2dc7df 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -919,8 +919,13 @@ - (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]; + ASCellNode *node = element.node; + if (element != nil && node != nil) { + height = [node layoutThatFits:element.constrainedSize].size.height; + } #if TARGET_OS_IOS /** From de8f288dbf02a6c66b2e0d7d4327aa27796233bf Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Fri, 25 May 2018 19:51:44 +0300 Subject: [PATCH 2/6] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecdf13ec0..486409c04 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 invalid layout of a cell node during height query. [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) From f9c6ab849c1b3c32c7756eb451f54f63a6c39073 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Fri, 25 May 2018 20:03:00 +0300 Subject: [PATCH 3/6] Assert node not nil --- Source/ASCollectionView.mm | 6 ++++-- Source/ASTableView.mm | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index b80da8557..a5f4f7f1c 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -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; diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 59c2dc7df..9027ef080 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -922,8 +922,9 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa CGFloat height = 0.0; ASCollectionElement *element = [_dataController.visibleMap elementForItemAtIndexPath:indexPath]; - ASCellNode *node = element.node; - if (element != nil && node != nil) { + if (element != nil) { + ASCellNode *node = element.node; + ASDisplayNodeAssertNotNil(node, @"Node must not be nil!"); height = [node layoutThatFits:element.constrainedSize].size.height; } From 444f3ff206cc45b6a4ccdbbba3c4dd705300830e Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Fri, 25 May 2018 20:06:37 +0300 Subject: [PATCH 4/6] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 486409c04..bba58ac8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +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 invalid layout of a cell node during height query. [Huy Nguyen](https://github.com/nguyenhuy) [#942](https://github.com/TextureGroup/Texture/pull/942) +- [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) From ebd20cce14e377873306be66ae4568bb9b6e3bab Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 28 May 2018 17:13:35 +0300 Subject: [PATCH 5/6] Fix failing test --- Source/ASTableView.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 9027ef080..51cb1390d 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -1825,6 +1825,9 @@ - (void)didLayoutSubviewsOfTableViewCell:(_ASTableViewCell *)tableViewCell const CGSize calculatedSize = [node layoutThatFits:constrainedSize].size; node.frame = { .size = calculatedSize }; + // Now that the node has been re-measured with a new constrained size, set the size to the backing colleciton element. + node.collectionElement.constrainedSize = constrainedSize; + // If the node height changed, trigger a height requery. if (oldSize.height != calculatedSize.height) { [self beginUpdates]; From 6c7564ea18442b63c809728535b654e3295b8cb9 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 28 May 2018 17:15:46 +0300 Subject: [PATCH 6/6] Slightly better comment --- Source/ASTableView.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 51cb1390d..861c0c934 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -1825,7 +1825,7 @@ - (void)didLayoutSubviewsOfTableViewCell:(_ASTableViewCell *)tableViewCell const CGSize calculatedSize = [node layoutThatFits:constrainedSize].size; node.frame = { .size = calculatedSize }; - // Now that the node has been re-measured with a new constrained size, set the size to the backing colleciton element. + // 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.