Add custom cells

Last Updated - Platform 19.0 - SDK 14.0

This guide will walk through how to present cells for links and adverts driven by the CartContentBlock types .link and .custom.

Before you begin

  1. 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.

  1. Set up your data layer and domain mappers to forward data required to present the cells to the presentation layer.
  2. 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

  1. Create a new file named ClientCartViewDataSource in an appropriate location such as Sources/Screens/Cart.
  2. Subclass the CartViewDataSource.
  3. Override the setup(for tableView:) function and call super.
  4. Register your custom cells using tableView.register(CustomCell.self).
  5. 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.

  1. Open your AppModule and navigate to the setUpCart function.
  2. 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()
  1. Run your app and check out your new cells.

You have added your custom cells to the Cart!