import React, { ReactNode, useState } from 'react'; import { PlayerConfiguration, THEOplayer, THEOplayerView } from 'react-native-theoplayer'; import { DEFAULT_THEOPLAYER_THEME, THEOplayerTheme } from './THEOplayerTheme'; import { Platform, StyleProp, View, ViewStyle } from 'react-native'; import { TestIDs } from './utils/TestIDs'; import type { Locale } from './components/util/Locale'; import { AirplayButton, AutoFocusGuide, CenteredControlBar, CenteredDelayedActivityIndicator, ChromecastButton, ControlBar, FullscreenButton, FULLSCREEN_CENTER_STYLE, MuteButton, PipButton, PlaybackRateSubMenu, PlayButton, QualitySubMenu, SeekBar, SettingsMenuButton, SkipButton, Spacer, TimeLabel, UiContainer, LanguageMenuButton, CastMessage, AdClickThroughButton, AdDisplay, AdCountdown, AdSkipButton, GoToLiveButton, } from '..'; export enum UIFeature { Chromecast, AirPlay, Fullscreen, Language, Mute, PiP, PlaybackRate, SeekBar, TrickPlay, VideoQuality, } // By default, exclude Chromecast, for which an extra dependency is needed. const defaultExcludedFeatures = [UIFeature.Chromecast]; export interface THEOplayerDefaultUiProps { /** * The style for the container. */ style?: StyleProp; /** * The theme for all components. */ theme?: Partial; /** * The localized strings used in the UI components. */ locale?: Partial; /** * The player configuration with THEOplayer license. */ config?: PlayerConfiguration; /** * The callback that is called when the internal THEOplayer is created. * @param player the internal THEOplayer */ onPlayerReady?: (player: THEOplayer) => void; /** * A slot in the top right to add additional UI components. */ topSlot?: ReactNode; /** * A slot in the bottom right to add additional UI components. */ bottomSlot?: ReactNode; /** * A set of features to exclude from the UI. * * @default [Cast] */ excludedFeatures?: UIFeature[]; } /** * A default UI layout which uses UI components from `react-native-theoplayer` to create a basic playback UI around a THEOplayerView. */ export function THEOplayerDefaultUi(props: THEOplayerDefaultUiProps) { const { theme, config, topSlot, bottomSlot, style, locale, excludedFeatures = defaultExcludedFeatures } = props; const [player, setPlayer] = useState(undefined); const onPlayerReady = (player: THEOplayer) => { setPlayer(player); props.onPlayerReady?.(player); }; return ( {player !== undefined && ( } top={ {topSlot} {!Platform.isTV && ( <> {!excludedFeatures.includes(UIFeature.AirPlay) && } {!excludedFeatures.includes(UIFeature.Chromecast) && } )} {!excludedFeatures.includes(UIFeature.Language) && } {!excludedFeatures.includes(UIFeature.VideoQuality) && } {!excludedFeatures.includes(UIFeature.PlaybackRate) && } } center={ : <>} middle={} right={!excludedFeatures.includes(UIFeature.TrickPlay) ? : <>} /> } bottom={ {!Platform.isTV && !excludedFeatures.includes(UIFeature.Chromecast) && !excludedFeatures.includes(UIFeature.AirPlay) && ( )} {!excludedFeatures.includes(UIFeature.SeekBar) && } {!excludedFeatures.includes(UIFeature.Mute) && } {bottomSlot} {!excludedFeatures.includes(UIFeature.PiP) && } {!excludedFeatures.includes(UIFeature.Fullscreen) && } } adTop={ } adCenter={ } /> } adBottom={ } /> )} ); }