-
Notifications
You must be signed in to change notification settings - Fork 18
/
HostLivestreamTopView.tsx
108 lines (104 loc) · 3.05 KB
/
HostLivestreamTopView.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React from 'react';
import { StyleSheet, View, ViewProps } from 'react-native';
import {
DurationBadge as DefaultDurationBadge,
DurationBadgeProps,
} from './DurationBadge';
import {
LiveIndicator as DefaultLiveIndicator,
LiveIndicatorProps,
} from './LiveIndicator';
import {
FollowerCount as DefaultFollowerCount,
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<DurationBadgeProps> | null;
/**
* Component to customize the Live indicator on the host's live stream's top view.
*/
LiveIndicator?: React.ComponentType<LiveIndicatorProps> | null;
/**
* Component to customize the Follower count indicator on the host's live stream's top view.
*/
FollowerCount?: React.ComponentType<FollowerCountProps> | 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 (
<View
style={[
styles.container,
{ backgroundColor: colors.static_overlay },
hostLivestreamTopView.container,
]}
onLayout={onLayout}
>
<View style={[styles.leftElement, hostLivestreamTopView.leftElement]}>
{DurationBadge && <DurationBadge mode="host" />}
</View>
<View
style={[styles.centerElement, hostLivestreamTopView.centerElement]}
/>
<View style={[styles.rightElement, hostLivestreamTopView.rightElement]}>
<View style={[styles.liveInfo, hostLivestreamTopView.liveInfo]}>
{liveOrBroadcasting && LiveIndicator && <LiveIndicator />}
{FollowerCount && <FollowerCount />}
</View>
</View>
</View>
);
};
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',
},
});