-
Notifications
You must be signed in to change notification settings - Fork 285
Home Screen
Home screen was built on the idea that view depends on data and when the data or state is changed the view is changed respectively.
The home screen consists of several parts:
-
HomeInteractor
contains business logic and model of home screen; -
HomeLayout
describes composition, position and size of cells on home screen; -
HomeViewController
works as usual controller, it connects Model and View.
If you have a look on Home screen in the simulator or on your device you will see just a table.
At first glance it may seem here is UITableView
, but it doesn't. We use UICollectionView
with compositional layout.
We create and configure this compositional layout in HomeLayout
class.
To show content on home screen we need to provide array of sections - SectionConfiguration
.
SectionConfiguration
is typealias (Section, [CollectionViewCellConfiguratorAny])
. Section
is just enum, but CollectionViewCellConfiguratorAny
is more interesting part here, it's type-erased protocol, which allow us to provide any type of model for cell, we called it configurators.
HomeViewController
gets these section information from HomeInteractor
. HomeInteractor
builds sections for HomeViewController
and update them. How 'HomeInteractor' understand what type of cell it has to build and update? It gets these information from State
.
State
is a set of data which represents the state of specific screen.
State
of HomeInteractor
receives updates from a level above, below you can see the this chain.
SceneDelegate
-> Coordinator
-> HomeViewController
-> HomeInteractor
So, for example, if we have new risk status, the state in SceneDelegate
will be changed and than it triggers update of level below - Home screen. When state of HomeInteractor is changed it triggers a method of rebuilding sections and after that UI will be updated.
- Create new cell, for example,
HomeNewCollectionViewCell
and conformHomeCardCollectionViewCell
protocol; - Create new configurator
HomeNewCellConfigurator
, this configurator should confirmHomeRiskCellConfigurator
protocol; - Implement required methods, especially for
Hashable
protocol; - Create the instance of new configurator in
HomeInteractor
and provide it to right place insections
.
- You have the access to instance of corresponding configurator;
- You update properties of this configurator;
- You call
reloadData
inHomeViewController
.