TKUIHomeComponentViewModel

@MainActor
public protocol TKUIHomeComponentViewModel

This protocol defines the requirements for any view models that may display their contents in a TKUIHomeCard.

  • This builds an instance of a view model whose contents may be displayed in a TKUIHomeCard

    Declaration

    Swift

    static func buildInstance(from inputs: TKUIHomeComponentInput) -> Self

    Parameters

    inputs

    The inputs from a TKUIHomeCard, which may be used by a component view model

  • A unique identifier for this component

    Declaration

    Swift

    var identity: String { get }
  • customizerItem Default implementation

    How this component should appear in the card customizer

    Return nil if it should not be included in the customizer

    Default Implementation

    Declaration

    Swift

    var customizerItem: TKUIHomeCardCustomizerItem? { get }
  • This closure returns an sequence whose element is a model used to populate a section of the table view in a TKUIHomeCard.

    You can hide a section dynamically by using items == nil. A section with empty items will still show just its header.

    Declaration

    Swift

    var homeCardSection: Driver<TKUIHomeComponentContent> { get }
  • nextAction Default implementation

    This returns an action in response to selecting a row in the section returned by homeCardSection.

    Default Implementation

    Declaration

    Swift

    var nextAction: Signal<TKUIHomeCard.ComponentAction> { get }
  • This returns a cell that is used to display a row in the section returned by homeCardSection

    The section property of the indexPath parameter corresponds to the position of the component view model in the list of view models passed to a TKUIHomeViewModel. As such, it may change as other component view models are added or removed. It is best not to use the section property when configuring the returned cell.

    Declaration

    Swift

    func cell(for item: TKUIHomeComponentItem, at indexPath: IndexPath, in tableView: UITableView) -> UITableViewCell?

    Parameters

    item

    The data model used to construct the cell

    indexPath

    The index path at which the item is located

    tableView

    The table view in which the cell is displayed

  • registerCell(with:) Default implementation

    This provides a component view model an opportunity to register the cell class with the table view in a TKUIHomeCard

    Default Implementation

    Declaration

    Swift

    func registerCell(with tableView: UITableView)

    Parameters

    tableView

    The table view with which the cell class is registered

  • This gives a component view model an opportunity to specify what actions to display with a home card component item when the leading edge of the cell corresponding to the item is swiped

    Typical, this method should only return an action configuration if the component view model is able to handle the incoming item.

    Warning

    This is only called if your item returns true to canEdit

    The section property of the indexPath parameter corresponds to the position of the component view model in the list of view models passed to a TKUIHomeViewModel. As such, it may change as other component view models are added or removed. It is best not to use the section property when configuring the returned cell.

    Default Implementation

    Declaration

    Swift

    func leadingSwipeActionsConfiguration(for item: TKUIHomeComponentItem, at indexPath: IndexPath, in tableView: UITableView) -> UISwipeActionsConfiguration?

    Parameters

    item

    The data model representing the cell whose leading edge is swiped

    indexPath

    The index path at which the item is located

    tableView

    The table view in which the item is displayed

  • This gives a component view model an opportunity to specify what actions to display with a home card component item when the trailing edge of the cell corresponding to the item is swiped.

    Typical, this method should only return an action configuration if the component view model is able to handle the incoming item.

    Warning

    This is only called if your item returns true to canEdit

    The section property of the indexPath parameter corresponds to the position of the component view model in the list of view models passed to a TKUIHomeViewModel. As such, it may change as other component view models are added or removed. It is best not to use the section property when configuring the returned cell.

    Default Implementation

    Declaration

    Swift

    func trailingSwipeActionsConfiguration(for item: TKUIHomeComponentItem, at indexPath: IndexPath, in tableView: UITableView) -> UISwipeActionsConfiguration?

    Parameters

    item

    The data model representing the cell whose trailing edge is swiped

    indexPath

    The index path at which the item is located

    tableView

    The table view in which the item is displayed

  • contextMenuConfiguration(for:at:in:) Default implementation

    This gives a component view model an opportunity to specify what actions to display with a home card component item when the context menu of the cell corresponding to the item is triggered.

    Typical, this method should only return an action configuration if the component view model is able to handle the incoming item.

    The section property of the indexPath parameter corresponds to the position of the component view model in the list of view models passed to a TKUIHomeViewModel. As such, it may change as other component view models are added or removed. It is best not to use the section property when configuring the returned cell.

    Default Implementation

    Declaration

    Swift

    func contextMenuConfiguration(for item: TKUIHomeComponentItem, at indexPath: IndexPath, in tableView: UITableView) -> UIContextMenuConfiguration?

    Parameters

    item

    The data model representing the cell whose context menu was triggered

    indexPath

    The index path at which the item is located

    tableView

    The table view in which the item is displayed