You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ji...@apache.org on 2019/06/14 07:04:39 UTC
[incubator-weex] branch master updated: [iOS] Fix iOS crash that a
header is inserted to list,
and splitting cells calculation incorrectly. (#2548)
This is an automated email from the ASF dual-hosted git repository.
jianhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
The following commit(s) were added to refs/heads/master by this push:
new 6a16112 [iOS] Fix iOS crash that a header is inserted to list, and splitting cells calculation incorrectly. (#2548)
6a16112 is described below
commit 6a16112c4858fc68b901e6db9618524854dc3734
Author: wqyfavor <qi...@taobao.com>
AuthorDate: Fri Jun 14 15:04:35 2019 +0800
[iOS] Fix iOS crash that a header is inserted to list, and splitting cells calculation incorrectly. (#2548)
---
.../WeexSDK/Sources/Component/WXListComponent.mm | 34 +++++++++++++++++++---
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm
index f01e81c..570214e 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm
@@ -334,13 +334,39 @@
&& [subcomponent isKindOfClass:[WXHeaderComponent class]]) {
// insert a header in the middle, one section may divide into two
// so the original section need to be reloaded
- NSIndexPath *indexPathBeforeHeader = [self indexPathForSubIndex:index - 1];
- if (_sections[insertIndex - 1].rows.count != 0 && indexPathBeforeHeader.row < _sections[insertIndex - 1].rows.count - 1) {
+
+ /*
+ Here we may encounter a problem that _sections is not always containing all cells of list.
+ Because cell are not added to _sections until cellDidLayout. So if a cell is not added to _sections,
+
+ NSIndexPath *indexPathBeforeHeader = [self indexPathForSubIndex:index - 1];
+ The indexPathForSubIndex method use all sub components of list to calculate row in section. This would
+ be incorrect if a cell is not added to _sections. And the split is incorrect resulting some cells put to
+ wrong WXSectionComponent and then UITableView crash.
+
+ In fixed version, we use _subcomponents[index - 1] to get the last component that should be put to original section
+ and get the index of it in section rows.
+ */
+
+ if (_sections[insertIndex - 1].rows.count > 0) {
+ WXComponent* componentBeforeHeader = _subcomponents[index - 1];
+
reloadSection = _sections[insertIndex - 1];
NSArray *rowsToSeparate = reloadSection.rows;
- insertSection.rows = [[rowsToSeparate subarrayWithRange:NSMakeRange(indexPathBeforeHeader.row + 1, rowsToSeparate.count - indexPathBeforeHeader.row - 1)] mutableCopy];
- reloadSection.rows = [[rowsToSeparate subarrayWithRange:NSMakeRange(0, indexPathBeforeHeader.row + 1)] mutableCopy];
+ NSUInteger indexOfLastComponentAfterSeparate = [rowsToSeparate indexOfObject:componentBeforeHeader];
+
+ insertSection.rows = [[rowsToSeparate subarrayWithRange:NSMakeRange(indexOfLastComponentAfterSeparate + 1, rowsToSeparate.count - (indexOfLastComponentAfterSeparate + 1))] mutableCopy];
+ reloadSection.rows = [[rowsToSeparate subarrayWithRange:NSMakeRange(0, indexOfLastComponentAfterSeparate + 1)] mutableCopy];
}
+
+// This is wrong!!!
+// NSIndexPath *indexPathBeforeHeader = [self indexPathForSubIndex:index - 1];
+// if (_sections[insertIndex - 1].rows.count != 0 && indexPathBeforeHeader.row < _sections[insertIndex - 1].rows.count - 1) {
+// reloadSection = _sections[insertIndex - 1];
+// NSArray *rowsToSeparate = reloadSection.rows;
+// insertSection.rows = [[rowsToSeparate subarrayWithRange:NSMakeRange(indexPathBeforeHeader.row + 1, rowsToSeparate.count - indexPathBeforeHeader.row - 1)] mutableCopy];
+// reloadSection.rows = [[rowsToSeparate subarrayWithRange:NSMakeRange(0, indexPathBeforeHeader.row + 1)] mutableCopy];
+// }
}
[_sections insertObject:insertSection atIndex:insertIndex];