Customize product card using the custom view(restricted API) React Native

This is a restricted API and we only support that on iOS now.

iOS

  1. Create a custom view class to implement the ProductCardViewRepresentable protocol.

import FireworkVideo

class CustomProductView: UIView, ProductCardViewRepresentable {
    lazy var label: UILabel = UILabel(frame: .zero)
    lazy var detailsLabel: UILabel = .init(frame: .zero)
    
    /**
     Called before a product card is reused.
     - Note: This is an opportunity to clean up the product card UI elements
     */
     func prepareForReuse() {
         label.text = ""
         detailsLabel.text = ""
     }
  
     /**
      Called before a product card will be displayed on screen
      - Important: It is best to avoid network calls when this method is invoked. The product card is just moments from being rendered and network calls
      at this stage would provide a degraded user experience. Please use the hydration API to perform any product data updates.
      - Note: This is the opportunity to update the product card UI with product specific details
      - Parameters:
       - product: The product details associated to the view that will be displayed
       - video: The details of the video the product is associated with.
     */
     func updateViewForProduct(_ product: ProductCardDetails, associatedTo video: VideoDetails) {
         label.text = product.name
         detailsLabel.text = "$\(product.price.amount)"
     }
}
  1. Call FireworkVideoSDK.shopping.productCardViewType = CustomProductView.self at the appropriate place, such as application(:, didFinishLaunchingWithOptions:) -> Bool.

import FireworkVideo

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    FireworkVideoSDK.shopping.productCardViewType = CustomProductView.self
    
    return true
}

Android

Custom product cards are disabled for the client by default. To enable this feature, the Firework SDK allows providing a custom view for the product card. This way, it is possible to have full control over the look and feel of the product card. To enable this feature, the host app should pass the following product card configuration:

FireworkSdk.shopping.setShoppingViewOptions(
    ShoppingViewOptions(
        theme = getProductCardsTheme(),
        productCardsOptions = ProductCardsOptions.Custom(
            widthPx = width,
            heightPx = height,
            spaceBetweenItems = spaceBetweenItems,
            cardViewStartEndPadding = padding,
            customViewProvider = { MyCustomProductCard(this) },
        ),
    ),
)

Provide a view for the custom product card. To pass a view for the custom product card, the host app should provide a customViewProvider parameter. This parameter is a factory function with the following signature:

val customViewProvider: () -> FwProductCardView

The function returns the implementation of FwProductCardView. FwProductCardView is an abstract class with a single abstract method that gets called when the card is inflated by FireworkSDK.

    abstract fun bind(product: ProductCardDetails, videoInfo: VideoInfo)

ProductCardDetails and VideoInfo contain information about the product and the video related to the product card. Here is an example of FwProductCardView implementation (initialization of the fields is omitted):

class MyCustomProductCard @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyle: Int = 0,
) : FwProductCardView(context, attrs, defStyle) {
    
    init {
        inflate(context, R.layout.custom_product_card_item, this)
    }

    override fun bind(product: ProductCardDetails, videoInfo: VideoInfo) {
        title.text = product.productTitle
        price.text = "${product.price?.amount ?: 0.0} ${product.price?.currencyCode}"
        Glide.with(image.context)
            .load(product.productImageUrl)
            .placeholder(R.drawable.ic_product_placeholder)
            .error(R.drawable.ic_product_placeholder)
            .into(image)
    }
}

Width and height of the custom product card. The width and height of the custom product card should be specified in pixels. The FireworkSDK can limit the size of the product card if it does not respect the safe zone. Details of the Safe Zone Specifications for Firework Videos can be found here - https://help.firework.com/safe-zone-specifications-for-firework-videos

Clickable elements on the custom product card. FireworkSDK does not allow to have clickable elements on the custom product card. If the custom product card has clickable elements, the click will be intercepted by the FireworkSDK and the default behavior will be triggered.

Last updated