UNPKG

@zezosoft/zezo-ott-react-native-video-player

Version:

React Native OTT Video Player for Android & iOS. Supports playlists, seasons, auto-next playback, subtitles, theming, analytics, fullscreen mode, and custom controls. 🚀 Powered by ZezoSoft.

48 lines (46 loc) • 1.5 kB
"use strict"; import { useEffect, useCallback, useRef } from 'react'; import { BackHandler, Platform, AppState } from 'react-native'; import { lockToPortrait } from "../lockOrientation.js"; import { useVideoPlayerStore } from "../../store/videoPlayerStore.js"; export const useVideoPlayerBack = ({ navigation } = {}) => { const { resetStore } = useVideoPlayerStore(); const hasClosed = useRef(false); // prevent multiple calls const handleClose = useCallback(() => { if (hasClosed.current) return; // prevent loop hasClosed.current = true; resetStore(); lockToPortrait(); if (navigation?.canGoBack()) { navigation.goBack(); } }, [resetStore, navigation]); useEffect(() => { const backHandler = Platform.OS === 'android' ? BackHandler.addEventListener('hardwareBackPress', () => { handleClose(); return true; }) : undefined; const unsubscribe = navigation?.addListener('beforeRemove', e => { e.preventDefault(); handleClose(); navigation.dispatch(e.data.action); }); const handleAppStateChange = nextAppState => { if (nextAppState === 'inactive') { handleClose(); } }; const appStateListener = AppState.addEventListener('change', handleAppStateChange); return () => { backHandler?.remove(); unsubscribe?.(); appStateListener.remove(); }; }, [handleClose, navigation]); return handleClose; }; //# sourceMappingURL=useVideoPlayerBack.js.map