mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Fix crashes in ASElementMap and ASMutableElementMap (#3090)
* Fix crashes in ASElementMap and ASMutableElementMap * testInitialRangeBounds to have a 10% maximum difference
This commit is contained in:
@@ -548,7 +548,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
||||
{
|
||||
// If this is a section index path, we don't currently have a method
|
||||
// to do a mapping.
|
||||
if (indexPath.row == NSNotFound) {
|
||||
if (indexPath == nil || indexPath.row == NSNotFound) {
|
||||
return indexPath;
|
||||
} else {
|
||||
NSIndexPath *viewIndexPath = [_dataController.visibleMap convertIndexPath:indexPath fromMap:_dataController.pendingMap];
|
||||
|
||||
@@ -54,8 +54,8 @@
|
||||
}
|
||||
s++;
|
||||
}
|
||||
for (NSDictionary *supsOfKind in [_supplementaryElements objectEnumerator]) {
|
||||
[supsOfKind enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *_Nonnull indexPath, ASCollectionElement * _Nonnull element, BOOL * _Nonnull stop) {
|
||||
for (NSDictionary *supplementariesForKind in [_supplementaryElements objectEnumerator]) {
|
||||
[supplementariesForKind enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *_Nonnull indexPath, ASCollectionElement * _Nonnull element, BOOL * _Nonnull stop) {
|
||||
[_elementToIndexPathMap setObject:indexPath forKey:element];
|
||||
}];
|
||||
}
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
- (nullable ASCollectionElement *)elementForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return ASGetElementInTwoDimensionalArray(_sectionsOfItems, indexPath);
|
||||
return (indexPath != nil) ? ASGetElementInTwoDimensionalArray(_sectionsOfItems, indexPath) : nil;
|
||||
}
|
||||
|
||||
- (nullable ASCollectionElement *)supplementaryElementOfKind:(NSString *)supplementaryElementKind atIndexPath:(NSIndexPath *)indexPath
|
||||
|
||||
@@ -226,6 +226,7 @@ NSArray *ASIndexPathsForMultidimensionalArray(NSArray *multidimensionalArray)
|
||||
|
||||
id ASGetElementInTwoDimensionalArray(NSArray *array, NSIndexPath *indexPath)
|
||||
{
|
||||
ASDisplayNodeCAssertNotNil(indexPath, @"Expected non-nil index path");
|
||||
ASDisplayNodeCAssert(indexPath.length == 2, @"Expected index path of length 2. Index path: %@", indexPath);
|
||||
NSInteger section = indexPath.section;
|
||||
if (array.count <= section) {
|
||||
|
||||
@@ -72,8 +72,8 @@ typedef NSMutableDictionary<NSString *, NSMutableDictionary<NSIndexPath *, ASCol
|
||||
[_sectionsOfItems removeObjectsAtIndexes:sections];
|
||||
} else {
|
||||
// Supplementaries
|
||||
NSMutableDictionary *supsForKind = _supplementaryElements[kind];
|
||||
[supsForKind removeObjectsForKeys:[sections as_filterIndexPathsBySection:supsForKind]];
|
||||
NSMutableDictionary *supplementariesForKind = _supplementaryElements[kind];
|
||||
[supplementariesForKind removeObjectsForKeys:[sections as_filterIndexPathsBySection:supplementariesForKind]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,12 @@ typedef NSMutableDictionary<NSString *, NSMutableDictionary<NSIndexPath *, ASCol
|
||||
if (kind == nil) {
|
||||
[_sectionsOfItems[indexPath.section] insertObject:element atIndex:indexPath.item];
|
||||
} else {
|
||||
_supplementaryElements[kind][indexPath] = element;
|
||||
NSMutableDictionary *supplementariesForKind = _supplementaryElements[kind];
|
||||
if (supplementariesForKind == nil) {
|
||||
supplementariesForKind = [NSMutableDictionary dictionary];
|
||||
_supplementaryElements[kind] = supplementariesForKind;
|
||||
}
|
||||
supplementariesForKind[indexPath] = element;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1031,7 +1031,7 @@
|
||||
r;
|
||||
});
|
||||
CGFloat expectedHeight = cn.bounds.size.height * 3;
|
||||
XCTAssertEqualWithAccuracy(CGRectGetHeight(preloadBounds), expectedHeight, 100);
|
||||
XCTAssertEqualWithAccuracy(CGRectGetHeight(preloadBounds), expectedHeight, expectedHeight * 0.1);
|
||||
XCTAssertEqual([[cn valueForKeyPath:@"rangeController.currentRangeMode"] integerValue], ASLayoutRangeModeMinimum, @"Expected range mode to be minimum before scrolling begins.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user