TKUICardAction

open class TKUICardAction<Card, Model> : ObservableObject where Card : TGCard

An action that can be added to a TKUI<*>Card. An array of these actions is typically generated by a factory method in a card’s configuration property, e.g., TKUITripOverviewCard.config.tripActionsFactory or TKUIServiceCard.config.serviceActionsFactory

For a concerte example, see TKUIStartTripAction.

If the action changes the state of the button itself, some care need to be taken that this is reflected:

func buildFavoriteAction(stop: TKUIStopAnnotation) -> TKUITimetableCard.Action {
  func isFavorite() -> Bool { FavoriteHelper.isFavorite(stop) }
  func title() -> String { isFavorite() ? "Remove" : "Add" }
  func icon() -> UIImage { isFavorite() ? UIImage.remove : UIImage.add }

  return TKUITimetableCard.Action(
    title: title, icon: icon
  ) { action, _, stop, _ in
    FavoriteHelper.toggleFavorite(stop)
  }
}

  • Initialises a new card action, which can be used to add custom buttons to a card that reflect some external state.

    Declaration

    Swift

    public init(
      content: AnyPublisher<TKUICardActionContent, Never>,
      priority: Int = 0,
      handler: @escaping @MainActor (TKUICardAction<Card, Model>, Card, Model, UIView) -> Void
    )

    Parameters

    content

    Publisher of the content for the button

    priority

    Priority of action to determine ordering in a list

    handler

    Handler executed when user taps on the button. Parameters are the owning card, the model instance, and the sender.

  • Initialises a new card action, which can be used to add custom buttons to a card.

    Declaration

    Swift

    public init(
      title: String,
      accessibilityLabel: String? = nil,
      icon: UIImage,
      style: TKUICardActionStyle = .normal,
      priority: Int = 0,
      isEnabled: Bool = true,
      handler: @escaping @MainActor (TKUICardAction<Card, Model>, Card, Model, UIView) -> Bool
    )

    Parameters

    title

    Action button title.

    accessibilityLabel

    Accessibility label to use for the button. Uses title if not provided.

    icon

    Icon to display as the action. Should be a template image.

    style

    Style for the button.

    priority

    Priority of action to determine ordering in a list

    isEnabled

    Set to false to show the button but disable it

    handler

    Handler executed when user taps on the button. Parameters are the action itself, the owning card, the model instance, and the sender. Should return whether the button should be refreshed, by calling the relevant “actions factory” again.

  • Initialises a new card action where the properties change depending on the handler.

    All the closures are called when first displaying the action, and after the handler is called on every tap.

    Declaration

    Swift

    public convenience init(
      title: @escaping () -> String,
      accessibilityLabel: (() -> String)? = nil,
      icon: @escaping () -> UIImage,
      style: (() -> TKUICardActionStyle)?  = nil,
      priority: Int = 0,
      isEnabled: Bool = true,
      handler: @escaping @MainActor (Card, Model, UIView) -> Void
    )

    Parameters

    title

    Provider of title for button.

    accessibilityLabel

    Provider of accessibility label for the button. Uses title if not provided.

    icon

    Provider of icon for the button. Should be a template image.

    style

    Provider of style for the button.

    priority

    Priority of action to determine ordering in a list

    isEnabled

    Set to false to show the button but disable it

    handler

    Handler executed when user taps on the button. Parameters are the owning card, the model instance, and the sender.

  • Title of the button

    Declaration

    Swift

    public var title: String { get set }
  • Accessibility label to use for the button

    Declaration

    Swift

    public var accessibilityLabel: String { get set }
  • Icon to display as the action. Should be a template image.

    Declaration

    Swift

    public var icon: UIImage { get set }
  • Undocumented

    Declaration

    Swift

    public var style: TKUICardActionStyle { get set }
  • Undocumented

    Declaration

    Swift

    public var isInProgress: Bool { get set }
  • Undocumented

    Declaration

    Swift

    public var isEnabled: Bool { get set }
  • Priority of the action to determine ordering in a list. Defaults to 0.

    If multiple actions have the same priority, then .bold style is preferred and otherwise by insertion order.

    Declaration

    Swift

    public var priority: Int
  • Handler executed when user taps on the button, providing the corresponding card and model instance. Should return whether the button should be refreshed as its title or icon changed as a result (e.g., for toggle actions such as adding or removing a reminder or favourite).

    Parameters are the action itself, the owning card, the model instance, and the sender.

    Declaration

    Swift

    public let handler: @MainActor (TKUICardAction<Card, Model>, Card, Model, UIView) -> Bool