Skip to content

Commit

Permalink
Forward preview providing methods too
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Sep 2, 2021
1 parent 7e9b9b9 commit 223ee4b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Source/IGListKit/IGListSectionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ NS_SWIFT_NAME(ListSectionController)
*/
- (UIContextMenuConfiguration * _Nullable)contextMenuConfigurationForItemAtIndex:(NSInteger)index point:(CGPoint)point API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);

/**
Tells the section controller that the cell has requested a preview for context menu highlight.
@param configuration Context menu configuration.
@return An object that conforms to `UITargetedPreview`
@note The default implementation does nothing. **Calling super is not required.**
*/
- (UITargetedPreview * _Nullable)previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);

/**
Tells the section controller that the cell has requested a preview for context menu dismiss.
@param configuration Context menu configuration.
@return An object that conforms to `UITargetedPreview`
@note The default implementation does nothing. **Calling super is not required.**
*/
- (UITargetedPreview * _Nullable)previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);

/**
Identifies whether an object can be moved through interactive reordering.
Expand Down
8 changes: 8 additions & 0 deletions Source/IGListKit/IGListSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ - (UIContextMenuConfiguration * _Nullable)contextMenuConfigurationForItemAtIndex
return nil;
}

- (UITargetedPreview * _Nullable)previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration {
return nil;
}

- (UITargetedPreview * _Nullable)previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration {
return nil;
}

- (BOOL)canMoveItemAtIndex:(NSInteger)index {
return NO;
}
Expand Down
36 changes: 35 additions & 1 deletion Source/IGListKit/Internal/IGListAdapter+UICollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

#import "IGListAdapterInternal.h"

@interface IGListAdapter ()

@property (nonatomic, strong) NSMapTable *configurationToSectionController;

@end

@implementation IGListAdapter (UICollectionView)

#pragma mark - UICollectionViewDataSource
Expand Down Expand Up @@ -278,7 +284,35 @@ - (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionVie
}

IGListSectionController * sectionController = [self sectionControllerForSection:indexPath.section];
return [sectionController contextMenuConfigurationForItemAtIndex:indexPath.item point:point];

UIContextMenuConfiguration *configuration = [sectionController contextMenuConfigurationForItemAtIndex:indexPath.item point:point];
if (configuration) {
if (!self.configurationToSectionController) {
self.configurationToSectionController = [NSMapTable weakToWeakObjectsMapTable];
}
[self.configurationToSectionController setObject:configuration forKey:sectionController];
}
return nil;
}

- (UITargetedPreview *)collectionView:(UICollectionView *)collectionView previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)){
id<UICollectionViewDelegate> collectionViewDelegate = self.collectionViewDelegate;
if ([collectionViewDelegate respondsToSelector:@selector(collectionView:previewForHighlightingContextMenuWithConfiguration:)]) {
return [collectionViewDelegate collectionView:collectionView previewForHighlightingContextMenuWithConfiguration:configuration];
}

IGListSectionController * sectionController = [self.configurationToSectionController objectForKey:configuration];
return [sectionController previewForHighlightingContextMenuWithConfiguration:configuration];
}

- (UITargetedPreview *)collectionView:(UICollectionView *)collectionView previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0)){
id<UICollectionViewDelegate> collectionViewDelegate = self.collectionViewDelegate;
if ([collectionViewDelegate respondsToSelector:@selector(collectionView:previewForDismissingContextMenuWithConfiguration:)]) {
return [collectionViewDelegate collectionView:collectionView previewForDismissingContextMenuWithConfiguration:configuration];
}

IGListSectionController * sectionController = [self.configurationToSectionController objectForKey:configuration];
return [sectionController previewForDismissingContextMenuWithConfiguration:configuration];
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions Source/IGListKit/Internal/IGListAdapterProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static BOOL isInterceptedSelector(SEL sel) {
sel == @selector(collectionView:didHighlightItemAtIndexPath:) ||
sel == @selector(collectionView:didUnhighlightItemAtIndexPath:) ||
sel == @selector(collectionView:contextMenuConfigurationForItemAtIndexPath:point:) ||
sel == @selector(collectionView:previewForHighlightingContextMenuWithConfiguration:) ||
sel == @selector(collectionView:previewForDismissingContextMenuWithConfiguration:) ||
// UICollectionViewDelegateFlowLayout
sel == @selector(collectionView:layout:sizeForItemAtIndexPath:) ||
sel == @selector(collectionView:layout:insetForSectionAtIndex:) ||
Expand Down

0 comments on commit 223ee4b

Please sign in to comment.