mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-06 15:08:50 +00:00
Summary: - Updated selectionDelegate to pass through the model object - Changelog entry under 3.0.0 as is breaking change Try saying single section selection 10 times quick Dabbing my left toe into some ObjC, so apologies if I violate years of rules - [ ] Update documentation internally Closes #396 - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/397 Differential Revision: D4406213 Pulled By: rnystrom fbshipit-source-id: ba468fa49e75823796a47da6ed7f0e8957db3d75
129 lines
5.1 KiB
Objective-C
129 lines
5.1 KiB
Objective-C
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import <IGListKit/IGListSectionController.h>
|
|
#import <IGListKit/IGListSectionType.h>
|
|
#import <IGListKit/IGListMacros.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
/**
|
|
A block used to configure cells.
|
|
|
|
@param item The model with which to configure the cell.
|
|
@param cell The cell to configure.
|
|
*/
|
|
typedef void (^IGListSingleSectionCellConfigureBlock)(id item, __kindof UICollectionViewCell *cell);
|
|
|
|
/**
|
|
A block that returns the size for the cell given the collection context.
|
|
|
|
@param item The model for the section.
|
|
@param collectionContext The collection context for the section.
|
|
|
|
@return The for the cell.
|
|
*/
|
|
typedef CGSize (^IGListSingleSectionCellSizeBlock)(id item, id<IGListCollectionContext> _Nullable collectionContext);
|
|
|
|
@class IGListSingleSectionController;
|
|
|
|
/**
|
|
A delegate that can receive selection events on an `IGListSingleSectionController`.
|
|
*/
|
|
@protocol IGListSingleSectionControllerDelegate <NSObject>
|
|
|
|
/**
|
|
Tells the delegate that the section controller was selected.
|
|
|
|
@param sectionController The section controller that was selected.
|
|
@param object The model for the given section.
|
|
*/
|
|
- (void)didSelectSectionController:(IGListSingleSectionController *)sectionController
|
|
withObject:(id)object;
|
|
|
|
@end
|
|
|
|
/**
|
|
This section controller is meant to make building simple, single-cell lists easier. By providing the type of cell, a block
|
|
to configure the cell, and a block to return the size of a cell, you can use an IGListAdapter-powered list simpler architecture.
|
|
*/
|
|
IGLK_SUBCLASSING_RESTRICTED
|
|
@interface IGListSingleSectionController : IGListSectionController <IGListSectionType>
|
|
|
|
/**
|
|
Creates a new section controller for a given cell type that will always have only one cell when present in a list.
|
|
|
|
@param cellClass The `UICollectionViewCell` subclass for the single cell.
|
|
@param configureBlock A block that configures the cell with the item given to the section controller.
|
|
@param sizeBlock A block that returns the size for the cell given the collection context.
|
|
|
|
@return A new section controller.
|
|
|
|
@warning Be VERY CAREFUL not to create retain cycles by holding strong references to: the object that owns the adapter
|
|
(usually `self`) or the `IGListAdapter`. Pass in locally scoped objects or use `weak` references!
|
|
*/
|
|
- (instancetype)initWithCellClass:(Class)cellClass
|
|
configureBlock:(IGListSingleSectionCellConfigureBlock)configureBlock
|
|
sizeBlock:(IGListSingleSectionCellSizeBlock)sizeBlock;
|
|
|
|
/**
|
|
Creates a new section controller for a given nib name and bundle that will always have only one cell when present in a list.
|
|
|
|
@param nibName The name of the nib file for the single cell.
|
|
@param bundle The bundle in which to search for the nib file. If nil, this method looks for the file in the main bundle.
|
|
@param configureBlock A block that configures the cell with the item given to the section controller.
|
|
@param sizeBlock A block that returns the size for the cell given the collection context.
|
|
|
|
@return A new section controller.
|
|
|
|
@warning Be VERY CAREFUL not to create retain cycles by holding strong references to: the object that owns the adapter
|
|
(usually `self`) or the `IGListAdapter`. Pass in locally scoped objects or use `weak` references!
|
|
*/
|
|
- (instancetype)initWithNibName:(NSString *)nibName
|
|
bundle:(nullable NSBundle *)bundle
|
|
configureBlock:(IGListSingleSectionCellConfigureBlock)configureBlock
|
|
sizeBlock:(IGListSingleSectionCellSizeBlock)sizeBlock;
|
|
|
|
/**
|
|
Creates a new section controller for a given storyboard cell identifier that will always have only one cell when present in a list.
|
|
|
|
@param identifier The identifier of the cell prototype in storyboard.
|
|
@param configureBlock A block that configures the cell with the item given to the section controller.
|
|
@param sizeBlock A block that returns the size for the cell given the collection context.
|
|
|
|
@return A new section controller.
|
|
|
|
@warning Be VERY CAREFUL not to create retain cycles by holding strong references to: the object that owns the adapter
|
|
(usually `self`) or the `IGListAdapter`. Pass in locally scoped objects or use `weak` references!
|
|
*/
|
|
- (instancetype)initWithStoryboardCellIdentifier:(NSString *)identifier
|
|
configureBlock:(IGListSingleSectionCellConfigureBlock)configureBlock
|
|
sizeBlock:(IGListSingleSectionCellSizeBlock)sizeBlock;
|
|
|
|
/**
|
|
An optional delegate that handles selection and deselection.
|
|
*/
|
|
@property (nonatomic, weak, nullable) id<IGListSingleSectionControllerDelegate> selectionDelegate;
|
|
|
|
/**
|
|
:nodoc:
|
|
*/
|
|
- (instancetype)init NS_UNAVAILABLE;
|
|
|
|
/**
|
|
:nodoc:
|
|
*/
|
|
+ (instancetype)new NS_UNAVAILABLE;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|