import { FWEventName } from './models/FWEventName'; import type PushRNContainerParams from './models/PushRNContainerParams'; import FWNavigatorModule, { FWNavigatorModuleEventEmitter, } from './modules/FWNavigatorModule'; import { Platform } from 'react-native'; /** * You can use this class for pushing RN page from the native page. */ class FWNavigator { private static _instance?: FWNavigator; public static getInstance(): FWNavigator { if (!FWNavigator._instance) { FWNavigator._instance = new FWNavigator(); } return FWNavigator._instance!; } private constructor() { FWNavigatorModuleEventEmitter.addListener(FWEventName.LogMessage, () => {}); } /** * Push a new RN container. * You could use this method to make a RN page on top of * SDK full-screen player. * @param params {PushRNContainerParams} * @returns {Promise} The result of pushing a new Container. */ public pushRNContainer(params: PushRNContainerParams): Promise { return FWNavigatorModule.pushRNContainer(params); } /** * Pop the RN container you pushed before. * @returns {Promise} The result of popping a new Container. */ public popRNContainer(): Promise { return FWNavigatorModule.popRNContainer(); } /** * Pop the native container. You could use the method to close the fullscreen player. * @returns {Promise} The result of popping the native container. */ public popNativeContainer(): Promise { return FWNavigatorModule.popNativeContainer(); } /** * Change current fullscreen player to floating player. * @returns {Promise} If the result is true, it means that the fullscreen * player is changed to floating player. */ public async startFloatingPlayer(): Promise { return FWNavigatorModule.startFloatingPlayer(); } /** * Stop current floating player. */ public async stopFloatingPlayer(): Promise { await FWNavigatorModule.stopFloatingPlayer(); } /** * @deprecated This API is deprecated and will be removed in the future. * Bring the RN container to top. * @returns {Promise} The result of presenting the RN container. * If the result is true, it means that the RN container is presented. * If the result is false, it means that the RN container is not presented. * Only supported on iOS */ public async bringRNContainerToTop(): Promise { if (Platform.OS === 'ios') { await new Promise((resolve) => setTimeout(resolve, 10)); return FWNavigatorModule.bringRNContainerToTop(); } else { return false; } } /** * @deprecated This API is deprecated and will be removed in the future. * Bring the RN container to bottom. * @returns {Promise} The result of dismissing the RN container. * If the result is true, it means that the RN container is dismissed. * If the result is false, it means that the RN container is not dismissed. * Only supported on iOS */ public async bringRNContainerToBottom(): Promise { if (Platform.OS === 'ios') { await new Promise((resolve) => setTimeout(resolve, 10)); return FWNavigatorModule.bringRNContainerToBottom(); } else { return false; } } /** * Try to transition the fullscreen player to Picture-in-Picture mode, * or alternatively, close the fullscreen player. * This API has no effect when no fullscreen player is present. * @returns whether the action is successful */ public async tryStartFloatingOrCloseFullScreen(): Promise { if (Platform.OS === 'ios') { return FWNavigatorModule.tryStartFloatingOrCloseFullScreen(); } else { let result = await this.startFloatingPlayer(); if (!result) { result = await this.popNativeContainer(); } return result; } } } export default FWNavigator;