import React from 'react'; import { StyleSheet, View, type ViewProps } from 'react-native'; import { DurationBadge as DefaultDurationBadge, type DurationBadgeProps, } from './DurationBadge'; import { LiveIndicator as DefaultLiveIndicator, type LiveIndicatorProps, } from './LiveIndicator'; import { FollowerCount as DefaultFollowerCount, type FollowerCountProps, } from './FollowerCount'; import { useTheme } from '../../../contexts'; import { useCallStateHooks } from '@stream-io/video-react-bindings'; import { Z_INDEX } from '../../../constants'; /** * Props for the HostLivestreamTopView component. */ export type HostLivestreamTopViewProps = { /** * Component to customize the Duration badge component on the host's live stream's top view. */ DurationBadge?: React.ComponentType | null; /** * Component to customize the Live indicator on the host's live stream's top view. */ LiveIndicator?: React.ComponentType | null; /** * Component to customize the Follower count indicator on the host's live stream's top view. */ FollowerCount?: React.ComponentType | null; onLayout?: ViewProps['onLayout']; }; /** * The HostLivestreamTopView component displays the top view component of the host's live stream. */ export const HostLivestreamTopView = ({ DurationBadge = DefaultDurationBadge, LiveIndicator = DefaultLiveIndicator, FollowerCount = DefaultFollowerCount, onLayout, }: HostLivestreamTopViewProps) => { const { useIsCallLive, useIsCallHLSBroadcastingInProgress } = useCallStateHooks(); const isCallLive = useIsCallLive(); const isBroadcasting = useIsCallHLSBroadcastingInProgress(); const liveOrBroadcasting = isCallLive || isBroadcasting; const { theme: { colors, hostLivestreamTopView }, } = useTheme(); return ( {DurationBadge && } {liveOrBroadcasting && LiveIndicator && } {FollowerCount && } ); }; const styles = StyleSheet.create({ container: { position: 'absolute', top: 0, flexDirection: 'row', alignItems: 'center', paddingVertical: 16, paddingHorizontal: 8, borderBottomEndRadius: 8, borderBottomStartRadius: 8, zIndex: Z_INDEX.IN_FRONT, }, liveInfo: { flexDirection: 'row', }, leftElement: { flex: 1, alignItems: 'flex-start', }, centerElement: { flex: 1, alignItems: 'center', }, rightElement: { flex: 1, alignItems: 'flex-end', }, });