Add custom cells
Last Updated - Platform 19.0 - SDK 14.0This guide will walk through how to present cells for links and adverts driven by the CartContentBlock
types .link
and .custom
.
Before you begin
- Create your cells ready for presenting in the Cart.
There is no need to over-engineer for an end-app solution; you do not need to separate into a protocol or put your view into containers.
- Set up your data layer and domain mappers to forward data required to present the cells to the presentation layer.
- Set up your domain to view data mappers to map the
CartContentBlock.link
or.custom
cases. We will use these in our below example.
Present your cells
- Create a new file named
ClientCartViewDataSource
in an appropriate location such asSources/Screens/Cart
. - Subclass the
CartViewDataSource
. - Override the
setup(for tableView:)
function and callsuper
. - Register your custom cells using
tableView.register(CustomCell.self)
. - Override the
cell(for item: ...)
function to implement custom dequeue logic.
Make sure to call super
for .cartItemCell
content block types to retain the default behaviour of the Cart.
- Open your
AppModule
and navigate to thesetUpCart
function. - Inject your data source for all instances of the Cart using Containers.
Container.shared.dataSources.cartViewDataSource = { ClientCartViewDataSource() }
Alternatively, you can pass your data source directly to the PoqCartView
for a single instance of the Cart.
CartBuilder() .withView(PoqCartView(dataSource: ClientCartViewDataSource())) .build()
- Run your app and check out your new cells.
You have added your custom cells to the Cart!