-
Notifications
You must be signed in to change notification settings - Fork 76
EpoxyBars
Eric Horacek edited this page Jan 28, 2021
·
5 revisions
EpoxyBars
is a declarative API to add fixed top and bottom bars to your UIViewController
. Adding these bars is simple:
final class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
topBarInstaller.install()
bottomBarInstaller.install()
}
private lazy var topBarInstaller = TopBarInstaller(viewController: self, bars: topBars)
private lazy var bottomBarInstaller = BottomBarInstaller(viewController: self, bars: bottomBars)
private var topBars: [BarModeling] {
[
// Instantiate BarModels for the top bars here
]
}
private var bottomBars: [BarModeling] {
[
// Instantiate BarModels for the bottom bars here
]
}
}
Each bar is represented by a BarModel
which follows the same conventions as all of the view models in Epoxy. You can create a BarModel
for any UIView
:
private var bottomBars: [BarModeling] {
[
BarModel<UIButton>(
params: UIButton.ButtonType.system,
content: "Buy Now",
makeView: UIButton.init(type:),
configureView: { context, content in
context.view.setTitle(content, for: .normal)
})
]
}
Calling setBars(_ bars: [BarModeling], animated: Bool)
will perform a diff between the given models and the current installed models. The bar installer will then update the UI to render the new set of bars and optionally animate the change.
Under the hood the bar installer will put each view into a container and render that container in the provided UIViewController's
view. It will update content insets accordingly and respect the safeAreaInsets
as well.
- Overview
ItemModel
andItemModeling
- Using
EpoxyableView
CollectionViewController
CollectionView
- Handling selection
- Setting view delegates and closures
- Highlight and selection states
- Responding to view appear / disappear events
- Using
UICollectionViewFlowLayout
- Overview
GroupItem
andGroupItemModeling
- Composing groups
- Spacing
StaticGroupItem
GroupItem
withoutEpoxyableView
- Creating components inline
- Alignment
- Accessibility layouts
- Constrainable and ConstrainableContainer
- Accessing properties of underlying Constrainables