When users click the CTA, the default behavior is rendering the CTA link content using the native web view. But the host app developers may want to render the CTA link content using the React Native page.
Scenario 2
When users click the cart icon, the host app may want to navigate the custom React Native cart page.
Issues
Both the CTA button and cart icon belong to the video player. There are similar issues in these two scenarios. As follows, when the video player is launched, the RN navigation stack is covered by the video player.
Generally, the host app use React Navigation library to handle the page navigation in RN App. And when the host app developers use the push method of React Navigation to navigate to the RN page in the above scenarios, the page will be rendered in the bottom RN navigation stack. Therefore, the new RN page would be covered by the video player(native page).
Solutions
We provide two solutions to handle these scenarios:
Start floating player
Make the RN page overlaying the full-screen player
Reordering RN container and native container
Start floating player
If the floating player is enabled, the host app could start the floating player when users click the CTA button or the cart icon.
FireworkSDK.getInstance().onCustomCTAClick=async (event) => {constresult=awaitFireworkSDK.getInstance().navigator.startFloatingPlayer();if (!result) {/* when the result is false, the current fullscreen player may not * enable the floating player. In that case, we could call the * following method to close the fullscreen player. */awaitFireworkSDK.getInstance().navigator.popNativeContainer(); }// Navigate to the RN webview page of the host app.navigation.navigate('LinkContent', { url:event.url });}
FireworkSDK.getInstance().shopping.onCustomClickCartIcon=async () => {constresult=awaitFireworkSDK.getInstance().navigator.startFloatingPlayer();if (!result) {/* when the result is false, the current fullscreen player may not * enable the floating player. In that case, we could call the * following method to close the fullscreen player. */awaitFireworkSDK.getInstance().navigator.popNativeContainer(); }// Navigate to the RN cart page of the host app.navigation.navigate('Cart');};
Make the RN page overlay the full-screen player
As shown below, we push a new RN container overlaying the full-screen player in this solution.
Create a new App component for the top RN container
The top app component and the bottom app component share the same memory. You could use the redux store to share the global app state.
In the first screen of the top RN container, you should call FireworkSDK.getInstance().navigator.popRNContainer() to close the top RN container when users click the header back button or Android hardware back button.
We provide bringRNContainerToTop API for bringing the bottom RN container to the front. When you want to navigate from the native page to the RN page, you could do the navigation on the RN container and call our API to bring the bottom RN container to the front. The sample codes are:
FireworkSDK.getInstance().onCustomCTAClick=async (event) => {// Do the navigation on the RN containerRootNavigation.navigate('LinkContent', {...params,// Mark the page is navigated from Firework native page. We should// call bringRNContainerToBottom when leaving this page. isFromNativeNavigation:true, });// Bring the bottom RN container to the frontawaitFireworkSDK.getInstance().navigator.bringRNContainerToTop();}
Bring the top RN container to the bottom
For example, the user is navigated to page A when clicking the CTA button. As the RN container is on the top, you need to pop the page on the RN container and call bringRNContainerToBottom when leaving page A. The sample codes are:
The following is the demo video. As the react-navigation library does the navigation when the view is shown, you can see the push navigation animation in the RN container when navigating to the RN page from the player.