Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Home Screen

Aleksandr TIkhonov edited this page Aug 24, 2020 · 2 revisions

Overview

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.

Sections and configurators

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

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.

FAQ

I want to add one more cell to Home Screen, what should I do?

  1. Create new cell, for example, HomeNewCollectionViewCell and conform HomeCardCollectionViewCell protocol;
  2. Create new configurator HomeNewCellConfigurator, this configurator should confirm HomeRiskCellConfigurator protocol;
  3. Implement required methods, especially for Hashable protocol;
  4. Create the instance of new configurator in HomeInteractor and provide it to right place in sections.

I want to update one of the cell on Home Screen, what should I do?

  1. You have the access to instance of corresponding configurator;
  2. You update properties of this configurator;
  3. You call reloadData in HomeViewController.

Links