Skip to content

Commit 223ee4b

Browse files
committed
Forward preview providing methods too
1 parent 7e9b9b9 commit 223ee4b

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

Source/IGListKit/IGListSectionController.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,28 @@ NS_SWIFT_NAME(ListSectionController)
132132
*/
133133
- (UIContextMenuConfiguration * _Nullable)contextMenuConfigurationForItemAtIndex:(NSInteger)index point:(CGPoint)point API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);
134134

135+
/**
136+
Tells the section controller that the cell has requested a preview for context menu highlight.
137+
138+
@param configuration Context menu configuration.
139+
140+
@return An object that conforms to `UITargetedPreview`
141+
142+
@note The default implementation does nothing. **Calling super is not required.**
143+
*/
144+
- (UITargetedPreview * _Nullable)previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);
145+
146+
/**
147+
Tells the section controller that the cell has requested a preview for context menu dismiss.
148+
149+
@param configuration Context menu configuration.
150+
151+
@return An object that conforms to `UITargetedPreview`
152+
153+
@note The default implementation does nothing. **Calling super is not required.**
154+
*/
155+
- (UITargetedPreview * _Nullable)previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);
156+
135157
/**
136158
Identifies whether an object can be moved through interactive reordering.
137159

Source/IGListKit/IGListSectionController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ - (UIContextMenuConfiguration * _Nullable)contextMenuConfigurationForItemAtIndex
101101
return nil;
102102
}
103103

104+
- (UITargetedPreview * _Nullable)previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration {
105+
return nil;
106+
}
107+
108+
- (UITargetedPreview * _Nullable)previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration {
109+
return nil;
110+
}
111+
104112
- (BOOL)canMoveItemAtIndex:(NSInteger)index {
105113
return NO;
106114
}

Source/IGListKit/Internal/IGListAdapter+UICollectionView.m

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
#import "IGListAdapterInternal.h"
2020

21+
@interface IGListAdapter ()
22+
23+
@property (nonatomic, strong) NSMapTable *configurationToSectionController;
24+
25+
@end
26+
2127
@implementation IGListAdapter (UICollectionView)
2228

2329
#pragma mark - UICollectionViewDataSource
@@ -278,7 +284,35 @@ - (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionVie
278284
}
279285

280286
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];
282316
}
283317
#endif
284318

Source/IGListKit/Internal/IGListAdapterProxy.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static BOOL isInterceptedSelector(SEL sel) {
3434
sel == @selector(collectionView:didHighlightItemAtIndexPath:) ||
3535
sel == @selector(collectionView:didUnhighlightItemAtIndexPath:) ||
3636
sel == @selector(collectionView:contextMenuConfigurationForItemAtIndexPath:point:) ||
37+
sel == @selector(collectionView:previewForHighlightingContextMenuWithConfiguration:) ||
38+
sel == @selector(collectionView:previewForDismissingContextMenuWithConfiguration:) ||
3739
// UICollectionViewDelegateFlowLayout
3840
sel == @selector(collectionView:layout:sizeForItemAtIndexPath:) ||
3941
sel == @selector(collectionView:layout:insetForSectionAtIndex:) ||

0 commit comments

Comments
 (0)