Widget delegate - React Native
Widgets within the application offer delegations, empowering developers to execute tailored actions in response to various events during the widget's lifecycle and viewer interactions. You can find more information about the different delegates functions on the native section here.
Declaration
<BlazeMomentsRowView
...,
widgetDelegate={
{
onDataLoadStarted: (event: OnDataLoadStartedEvent) => {
console.log('onWidgetDataLoadStarted - widgetId: ' + event.widgetId);
},
onDataLoadComplete: (event: OnDataLoadCompleteEvent) => {
console.log('onWidgetDataLoadCompleted - widgetId: ' + event.widgetId + ', itemCount: ' + event.itemsCount + ', error: ' + event.error);
},
onPlayerDidAppear: (event: OnPlayerDidAppearEvent) => {
console.log('onWidgetPlayerDidAppear - widgetId: ' + event.widgetId);
},
onPlayerDidDismiss: (event: OnPlayerDidDismissEvent) => {
console.log('onWidgetPlayerDismissed - widgetId: ' + event.widgetId);
},
onItemClicked: (event: OnItemClickedEvent) => {
console.log('onItemClicked - widgetId: ' + event.widgetId + ', widgetItemId: ' + event.widgetItemId + ', widgetItemTitle: ' + event.widgetItemTitle);
},
onTriggerCTA: (params: BlazeOnTriggerCTAParams) => {
console.log('onTriggerCTA - playerType: ' + params.playerType + ', actionType: ' + params.actionType + ', actionParam: ' + params.actionParam);
},
onTriggerPlayerBodyTextLink: (event: OnTriggerPlayerBodyTextLinkEvent) => {
console.log('onTriggerPlayerBodyTextLink - widgetId: ' + event.widgetId + ', actionParam: ' + event.actionParam);
},
onPlayerEventTriggered: (event: OnPlayerEventTriggeredEvent) => {
switch (event.playerEvent.type) {
case 'OnMomentStart': {
console.log('onPlayerEventTriggered - widgetId: ' + event.widgetId + ' playerEvent: MomentId ' + event.playerEvent.momentId);
break
}
case 'OnStoryStart': {
console.log('onPlayerEventTriggered - widgetId: ' + event.widgetId + ' playerEvent: StoryId ' + event.playerEvent.storyId);
break
}
case 'OnVideoStart': {
console.log(widgetName + ' - onPlayerEventTriggered - widgetId: ' + event.widgetId + 'playerEvent: StoryId ' + event.playerEvent.videoId);
break
}
}
},
}
}
/>
onTriggerCTA
Called when a viewer taps a CTA button in a player opened from this widget. Available on widgetDelegate and on momentsContainerTabsDelegate.
The callback is a notification and returns nothing. Who opens the link is set in advance by the widget's appOverridesCTAHandling prop: with false (the default), the SDK opens it. Open the link yourself only when you set the prop to true.
In a Moments widget that uses tabsConfiguration, CTAs from the tabs player arrive on momentsContainerTabsDelegate, not on widgetDelegate.
Its BlazeOnTriggerCTAParams:
playerType: The player the CTA was tapped in.sourceId: The id of the content source, when available.actionType:'Deeplink'or'Web'.actionParam: The link assigned to the CTA.
The SDK doesn't close the player on a CTA tap. If your app navigates to its own screen, call dismissPlayer first.
onTriggerInteractionLink
Added in React Native SDK 1.21.0. Called when an interaction (engagement layer) inside a Stories or Moments player asks to open a link. Available on widgetDelegate, on momentsContainerTabsDelegate, and on the player entry point delegate.
The callback is a notification and returns nothing. What the SDK does with the link is set in advance by interactionLinkHandling, on the widget (see interactionLinkHandling) or in InitOptions (see SDK configuration). Open the link yourself only when you declared 'Handled'; with 'Deeplink', 'Web', or nothing declared, the SDK opens it as well.
In a Moments widget that uses tabsConfiguration, links from the tabs player arrive on momentsContainerTabsDelegate, not on widgetDelegate.
Its BlazeOnTriggerInteractionLinkParams:
playerType: The player the interaction is in.sourceId: The id of the content source, when available. OnmomentsContainerTabsDelegate, it is formatted as<containerSourceId>_<containerId>.interactionId: The identifier of the interaction that requested the link.interactionType: The type of the interaction that requested the link, as a string.url: The URL requested by the interaction, as the interaction provided it.
On iOS, a URL that can't be parsed or has no scheme is ignored, so nothing opens, but the callback still fires. On Android, the URL is handed to the system as-is.
<BlazeMomentsRowView
...
interactionLinkHandling={'Handled'}
widgetDelegate={{
onTriggerInteractionLink: params => {
Linking.openURL(params.url);
},
}}
/>onContentRestricted
Added in React Native SDK 1.21.0. Called when an item can't be played because the viewer is not entitled to it. Playback of the refused item does not start, and the SDK shows no restriction UI of its own. reason decides the next step, and isRetriable says when trying again later is enough. Available on widgetDelegate, on momentsContainerTabsDelegate, and on the player entry point delegate.
The callback is an observer: it returns nothing, and the SDK's handling of the refused item does not depend on your app. Your app's response, such as a paywall, a sign-in, or a fresh viewer token through setExternalUserToken, is up to you. It is not called for players opened from showSearchScreen.
Its BlazeOnContentRestrictedParams:
playerType: The player the refused item is in.sourceId: The id of the content source, when available. OnmomentsContainerTabsDelegate, it is formatted as<containerSourceId>_<containerId>.reason: Why playback was refused, aBlazeContentRestrictionReason:'SubscriptionRequired','GeoBlocked','VpnBlocked','DeviceLimitReached','ContentNotAvailable','ExternalUserTokenMissing','ExternalUserTokenInvalid','ExternalUserTokenExpired','RateLimited','TemporarilyUnavailable', or'Unknown'.'Unknown'also covers reasons added after this SDK version.isRetriable: Whether the same request could succeed later without anything changing for the viewer.truefor'RateLimited'and'TemporarilyUnavailable'.contentParams: The refused item, aBlazeRestrictedContentParams:contentIndex: The zero-based index of the item in the list, ads excluded.contentId: The unique content ID of the refused item. For a story, the story, not the page.extraInfo: Content-level metadata for the item, as a map of strings. Empty when there is none.contentThumbnailUrl: The URL of the item's main thumbnail, absent when it has none.
On iOS, a restriction from a Moments tabs player tab that is not active is delivered when that tab becomes active. On Android, it is delivered immediately.
<BlazeMomentsRowView
...
widgetDelegate={{
onContentRestricted: params => {
if (params.reason === 'SubscriptionRequired') {
showPaywall(params.contentParams.contentId);
}
},
}}
/>For the concept and the end-to-end flow, see Content entitlements.
Moments tabs delegate
momentsContainerTabsDelegate is for BlazeMomentsRowView and BlazeMomentsGridView widgets that use tabsConfiguration.
Use it to receive tabs-player events for a specific widget instance. BlazePlayerContainerTabsDelegate includes onTabSelected, onTabReselected, and the standard player source callbacks, such as data-load, player appear or dismiss, CTA, custom action, onTriggerInteractionLink, and onContentRestricted callbacks.
<BlazeMomentsRowView
widgetId="home-moments-tabs"
tabsConfiguration={tabsConfiguration}
momentsContainerTabsDelegate={{
onTabSelected: event => {
console.log('Selected Moments tab:', event);
},
onPlayerDidAppear: event => {
console.log('Moments tabs player appeared:', event.widgetId);
},
onPlayerDidDismiss: event => {
console.log('Moments tabs player dismissed:', event.widgetId);
},
}}
/>onTabSelected
Called when a tab is selected. Not called when the selection lands on a hidden tab (isVisible: false on the tab in tabsConfiguration). On Android, it fires on the initial selection, on programmatic selection, and on swipes.
Changed in React Native SDK 1.21.0: on iOS, tabIndex is the index among visible tabs and the callback no longer fires for hidden tabs, matching Android. For example, with tabs [A, B (hidden), C], selecting C reports tabIndex 1, where iOS used to report 2. Apps that hide no tabs are unaffected.
Its BlazeOnTabSelectedParams:
playerType: The type of the player.sourceId: The combined source identifier, formatted as<containerSourceId>_<containerId>.tabIndex: The zero-based index of the selected tab among visible tabs, the same index reloadTab takes.
onTabReselected
Added in React Native SDK 1.21.0. Called when the viewer taps the title of the tab that is already selected. Not called for swipes or programmatic selection. Never called while the tab bar is hidden, which is the case for a single visible tab unless isTabTitleVisibleWhenSingleTab is set.
It receives the same BlazeOnTabSelectedParams as onTabSelected. tabIndex counts visible tabs, the same index reloadTab takes, so you can reload the tab the viewer tapped again:
const momentsRowRef = useRef<BlazeMomentsRowView | null>(null);
<BlazeMomentsRowView
ref={momentsRowRef}
widgetId="home-moments-tabs"
tabsConfiguration={tabsConfiguration}
momentsContainerTabsDelegate={{
onTabReselected: params => {
momentsRowRef.current?.reloadTab(params.tabIndex);
},
}}
/>Updated 10 days ago
