Instagram / Instagram/IGListKit

trait collections and ListSectionControllers

Open
#1,013 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Objective-C
Stars
13.1k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Has anyone done anything with changing trait collections (eg iPad splitviews) and section controllers and maybe formed some best practices or neat solutions around it?

In particular, I often need to update the minimum{Interitem,Line}Spacing values depending on the trait collection. So I made the following protocol:

```swift
protocol TraitCollectionAdaptable {
func traitCollectionDidChange(from previousTraitCollection: UITraitCollection?, to traitCollection: UITraitCollection)
}

extension ListAdapter {
// Call this from UIViewController.traitCollectionDidChange to propagate changes to supporting section controllers
func updateTraitCollectionsForVisibleSectionControllers(from previousTraitCollection: UITraitCollection?, to traitCollection: UITraitCollection) {
for controller in visibleSectionControllers().flatMap({ $0 as? TraitCollectionAdaptable }) {
controller.traitCollectionDidChange(from: previousTraitCollection, to: traitCollection)
}
}
}
```

I could make the IGListSectionControllers conform to `UITraitEnvironment`, but then I have to support a `traitCollection` property. Obviously, the downside to this approach is that you have to remember to call the update method in order to inform the section controllers that things have changed.

Does anyone have a better approach here?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.