|
18 | 18 |
|
19 | 19 | #import "IGListAdapterInternal.h" |
20 | 20 |
|
| 21 | +@interface IGListAdapter () |
| 22 | + |
| 23 | +@property (nonatomic, strong) NSMapTable *configurationToSectionController; |
| 24 | + |
| 25 | +@end |
| 26 | + |
21 | 27 | @implementation IGListAdapter (UICollectionView) |
22 | 28 |
|
23 | 29 | #pragma mark - UICollectionViewDataSource |
@@ -278,7 +284,35 @@ - (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionVie |
278 | 284 | } |
279 | 285 |
|
280 | 286 | IGListSectionController * sectionController = [self sectionControllerForSection:indexPath.section]; |
281 | | - return [sectionController contextMenuConfigurationForItemAtIndex:indexPath.item point:point]; |
| 287 | + |
| 288 | + UIContextMenuConfiguration *configuration = [sectionController contextMenuConfigurationForItemAtIndex:indexPath.item point:point]; |
| 289 | + if (configuration) { |
| 290 | + if (!self.configurationToSectionController) { |
| 291 | + self.configurationToSectionController = [NSMapTable weakToWeakObjectsMapTable]; |
| 292 | + } |
| 293 | + [self.configurationToSectionController setObject:configuration forKey:sectionController]; |
| 294 | + } |
| 295 | + return nil; |
| 296 | +} |
| 297 | + |
| 298 | +- (UITargetedPreview *)collectionView:(UICollectionView *)collectionView previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)){ |
| 299 | + id<UICollectionViewDelegate> collectionViewDelegate = self.collectionViewDelegate; |
| 300 | + if ([collectionViewDelegate respondsToSelector:@selector(collectionView:previewForHighlightingContextMenuWithConfiguration:)]) { |
| 301 | + return [collectionViewDelegate collectionView:collectionView previewForHighlightingContextMenuWithConfiguration:configuration]; |
| 302 | + } |
| 303 | + |
| 304 | + IGListSectionController * sectionController = [self.configurationToSectionController objectForKey:configuration]; |
| 305 | + return [sectionController previewForHighlightingContextMenuWithConfiguration:configuration]; |
| 306 | +} |
| 307 | + |
| 308 | +- (UITargetedPreview *)collectionView:(UICollectionView *)collectionView previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)){ |
| 309 | + id<UICollectionViewDelegate> collectionViewDelegate = self.collectionViewDelegate; |
| 310 | + if ([collectionViewDelegate respondsToSelector:@selector(collectionView:previewForDismissingContextMenuWithConfiguration:)]) { |
| 311 | + return [collectionViewDelegate collectionView:collectionView previewForDismissingContextMenuWithConfiguration:configuration]; |
| 312 | + } |
| 313 | + |
| 314 | + IGListSectionController * sectionController = [self.configurationToSectionController objectForKey:configuration]; |
| 315 | + return [sectionController previewForDismissingContextMenuWithConfiguration:configuration]; |
282 | 316 | } |
283 | 317 | #endif |
284 | 318 |
|
|
0 commit comments