From b367f7ceb25980644c902eeed197f6ba5d077f1a Mon Sep 17 00:00:00 2001 From: Brandon Kieft Date: Tue, 19 Oct 2021 08:48:07 -0700 Subject: [PATCH] Handle cases where the delegate is already an IGListAdapter Summary: I was assuming the delegate would always be an IGListAdapterProxy, but this only happens if the client sets either the `collectionViewDelegate` or `scrollViewDelegate` properties on IGListAdapter. Otherwise the delegate will just be the IGListAdapter. Change the debug code to handle this case. We were starting to see some debug logs roll in with the delegate class listed as IGListAdapter. Hopefully this will return the correct class now. Differential Revision: D31690438 fbshipit-source-id: bf6dde57756fee4fe617944d45e152cae734b4f1 --- Source/IGListKit/IGListCollectionViewLayout.mm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/IGListKit/IGListCollectionViewLayout.mm b/Source/IGListKit/IGListCollectionViewLayout.mm index e69ef50f..59a6ab9d 100644 --- a/Source/IGListKit/IGListCollectionViewLayout.mm +++ b/Source/IGListKit/IGListCollectionViewLayout.mm @@ -462,16 +462,18 @@ static void adjustZIndexForAttributes(UICollectionViewLayoutAttributes *attribut - (NSString *)_classNameForDelegate:(id)delegate sectionIndex:(NSInteger)section { NSString *const delegateClassString = NSStringFromClass(delegate.class); - if ([delegateClassString isEqualToString:@"IGListAdapterProxy"] == NO) { + const BOOL isListAdapter = [delegateClassString isEqualToString:@"IGListAdapter"]; + const BOOL isListAdapterProxy = [delegateClassString isEqualToString:@"IGListAdapterProxy"]; + if (isListAdapter == NO && isListAdapterProxy == NO) { return delegateClassString; } - id forwardingObject = [(id)delegate forwardingTargetForSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]; + const id forwardingObject = (isListAdapterProxy ? [(id)delegate forwardingTargetForSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] : delegate); if ([forwardingObject isKindOfClass:IGListAdapter.class] == NO) { return NSStringFromClass([forwardingObject class]); } - id sectionController = [forwardingObject sectionControllerForSection:section]; + const id sectionController = [forwardingObject sectionControllerForSection:section]; return NSStringFromClass([sectionController class]); }