-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cell preselection #524
Comments
@PharosProduction can you describe a bit what you're trying to do? The docs say:
If you're trying to do custom selection state, we recommend making your own properties and settings. |
There is a |
@PharosProduction at Instagram we use custom properties to represent selected state in our UI instead of relying on the
Then in |
Got it. Thanks. |
@PharosProduction you mean to use the |
No, on ViewController level. Actually I understand it's possible by digging inside IGListKit and changing current code, but maybe I'm wrong and I have missed something in docs. |
@PharosProduction it should be totally possible. That |
I have updated IGListKit to the latest master. It works, thank you. |
💯 |
Summary: Adding support for a cell deselection API. Trying to make some headway to move and drag+drop support, but also want better stock `UICollectionView` API support. Will also assist eventual `UITableView` support. - Added overridable API to `IGListSectionController` - Support for stacked SC - Breaking, required protocol for binding SC Assists #524 and #184 - [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. Closes #853 Reviewed By: jeremycohen Differential Revision: D5425414 Pulled By: rnystrom fbshipit-source-id: 0b25c125b1f171979a15c3095095fc18b4108be6
I know it might be a little late to solve this issue, but for those who still need to resolve this issue without too much hassle, you just need to call the override func cellForItem(at index: Int) -> UICollectionViewCell {
reusableCell(at: index, isNib: false) {
let item = self.items[safe: index]
$0.item = item
$0.isSelected = item?.isSelected ?? false
if item?.isSelected == true {
self.collectionContext.selectItem(at: index,
sectionController: self,
animated: false,
scrollPosition: [])
}
} as Cell
} Then the |
Here is the syntactic sugar I used for the previous comment: extension ListSectionController {
public func reusableCell<T: UICollectionViewCell>(at index: Int, isNib: Bool, configCell: ((T) -> Void)? = nil) -> T {
if isNib {
guard let cell = collectionContext?.dequeueReusableCell(withNibName: String(describing: T.self), bundle: nil, for: self, at: index) as? T else {
fatalError("Could not dequeeu nib cell of type: {\(type(of: T.self))}")
}
configCell?(cell)
return cell
} else {
guard let cell = collectionContext?.dequeueReusableCell(of: T.self, for: self, at: index) as? T else {
fatalError("Could not dequeeu class cell of type: {\(type(of: T.self))}")
}
configCell?(cell)
return cell
}
}
} |
I'm trying to preselect a cell in
cellForItem(at index: Int) -> UICollectionViewCell
bycell.isSelected = true
in section controller.It works fine and cell becomes selected. When I try to deselect a cell by tapping it cell doesn't react at all. Tap triggers
isHighlighted
method but doesn't want to trigger neitherisSelected
in cell nordidDeselectItemAt
delegate method.This issue is related only to preselected cells. All other cells work fine in the same collection.
The text was updated successfully, but these errors were encountered: