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
Create a custom view class to implement the ProductCardViewRepresentable protocol.
importFireworkVideoclassCustomProductView:UIView, ProductCardViewRepresentable {lazyvar label: UILabel =UILabel(frame: .zero)lazyvar 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 */funcprepareForReuse() { 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. */funcupdateViewForProduct(_product: ProductCardDetails, associatedTovideo: VideoDetails) { label.text= product.name detailsLabel.text="$\(product.price.amount)" }}
Call FireworkVideoSDK.shopping.productCardViewType = CustomProductView.self at the appropriate place, such as application(:, didFinishLaunchingWithOptions:) -> Bool.
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:
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):
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.