1 min read

Sort Selection

Last Updated - Platform 19.0.0 - SDK 14.0.0

Builders are the main setup and customisation point of a feature. However, containers can be used to customise standard dependencies of a feature for all instances of that feature.

The SortSelectionBuilder is constrained to a SortSelectionState where the default type is PoqSortSelectionState. It uses delegateMiddleware to apply the SortOrder selection to the Product List or previous feature.

The ProductListState has a sort sub-state that can be easily passed to the SortSelectionBuilder.

sort selection

Customise the sort feature

To customise the sort feature you will need to override the product list navigation middleware.

Create a new Swift file for the custom navigation middleware with the following code.

import PoqFoundation
import PoqProductList
extension Middleware where State : ProductListState {
static func customNavigation() -> Middleware {
Middleware { (store, action) in
guard let action = action as? NavigationAction else { return }
guard let destination = action.destination as? ProductListNavigationDestination else { return }
switch action {
case .sortSelection:
guard let sort = store.state?.sort else { return }
let viewController = SortSelectionBuilder()
.withDelegateMiddleware(using: store.dispatch)
.build(with: sort)
// Apply popover presentation.
viewController.modalPresentationStyle = .popover
viewController.popoverPresentationController?.sourceView = action.sourceView
// Modally present the sort feature.
// Otherwise execute the default middleware.
.execute(store: store, action: action)

You must provide delegate middleware to the SortSelectionBuilder within your code.

Open your AppModule and modify the ProductListBuilder variable that you set up earlier.

import PoqFoundation
import PoqProductList
class AppModule: PoqModule {
var productListBuilder: ProductListBuilder {

You have customised the sort feature.

Container customisation

Containers can be used to customise services, mappers, views and more by modifying your AppModule to inject custom implementations into Container.shared.

A good location for this code is at the beginning of the setUpProductList function, or in setUpDependencies for global dependencies. See the full list of dependencies, used by this feature, below.

Builder customisation

Example of basic usage.

let viewController = SortSelectionBuilder()
.withDelegateMiddleware(using: store.dispatch)
.build(with: state.sort)

Example of usage with custom view controller subclass.

let viewController: CustomSortSelectionViewController = SortSelectionBuilder()
.withDelegateMiddleware(using: store.dispatch)
.build(with: state.sort)

Example of usage with customisation.

let viewController = SortSelectionBuilder<CustomSortSelectionState>()
.withDelegateMiddleware(using: { (action) in
guard case SortSelectionAction.apply(let sortOrder) = action else { return store.dispatch(action) }
.build(with: SortSelectionState(available: [.featured, .priceHighToLow, .priceLowToHigh, .rating], selected: .featured))