-
Notifications
You must be signed in to change notification settings - Fork 18
/
IncomingCall.tsx
168 lines (159 loc) · 4.17 KB
/
IncomingCall.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import React from 'react';
import {
ImageBackground,
StyleSheet,
Text,
View,
ViewStyle,
} from 'react-native';
import {
useCallStateHooks,
useConnectedUser,
useI18n,
} from '@stream-io/video-react-bindings';
import { UserInfo } from './UserInfo';
import {
CallTopView as DefaultCallTopView,
CallTopViewProps,
} from '../CallTopView';
import {
IncomingCallControls as DefaultIncomingCallControls,
IncomingCallControlsProps,
} from '../CallControls';
import { useTheme } from '../../../contexts';
import { useApplyDefaultMediaStreamSettings } from '../../../hooks/useApplyDefaultMediaStreamSettings';
/**
* Props for the IncomingCall Component.
*/
export type IncomingCallProps = IncomingCallControlsProps & {
/**
* Prop to customize the CallTopView component in the IncomingCall component.
*/
CallTopView?: React.ComponentType<CallTopViewProps> | null;
/**
* Prop to customize the IncomingCall controls.
*/
IncomingCallControls?: React.ComponentType<IncomingCallControlsProps> | null;
/**
* Check if device is in landscape mode.
* This will apply the landscape mode styles to the component.
*/
landscape?: boolean;
};
/**
* An incoming call with the caller's avatar, name and accept/reject buttons.
* Used when the user is receiving a call.
*/
export const IncomingCall = ({
onAcceptCallHandler,
onRejectCallHandler,
CallTopView = DefaultCallTopView,
IncomingCallControls = DefaultIncomingCallControls,
landscape,
}: IncomingCallProps) => {
const { t } = useI18n();
const {
theme: { colors, incomingCall, typefaces },
} = useTheme();
useApplyDefaultMediaStreamSettings();
const landscapeContentStyles: ViewStyle = {
flexDirection: landscape ? 'row' : 'column',
};
return (
<Background>
{CallTopView && <CallTopView />}
<View
style={[styles.content, landscapeContentStyles, incomingCall.content]}
>
<View style={[styles.topContainer, incomingCall.topContainer]}>
<UserInfo />
<Text
style={[
styles.incomingCallText,
{ color: colors.static_white },
typefaces.heading6,
incomingCall.incomingCallText,
]}
>
{t('Incoming Call...')}
</Text>
</View>
<View style={[styles.bottomContainer, incomingCall.bottomContainer]}>
<View
style={[
styles.incomingCallControls,
incomingCall.incomingCallControls,
]}
>
{IncomingCallControls && (
<IncomingCallControls
onAcceptCallHandler={onAcceptCallHandler}
onRejectCallHandler={onRejectCallHandler}
/>
)}
</View>
</View>
</View>
</Background>
);
};
const Background: React.FunctionComponent<{
children: React.ReactNode;
}> = ({ children }) => {
const {
theme: { colors, incomingCall },
} = useTheme();
const connectedUser = useConnectedUser();
const { useCallMembers } = useCallStateHooks();
const members = useCallMembers();
// take the first N members to show their avatars
const avatarsToShow = (members || [])
.filter(({ user }) => user.id !== connectedUser?.id)
.map(({ user }) => user.image)
.filter((image): image is string => !!image);
if (avatarsToShow.length) {
return (
<ImageBackground
blurRadius={10}
source={{
uri: avatarsToShow[0],
}}
style={[
styles.background,
{ backgroundColor: colors.static_grey },
incomingCall.background,
]}
>
{children}
</ImageBackground>
);
}
return (
<View
style={[
styles.background,
{ backgroundColor: colors.static_grey },
incomingCall.background,
]}
>
{children}
</View>
);
};
export const styles = StyleSheet.create({
background: {
flex: 1,
},
content: {
flex: 1,
},
topContainer: { flex: 1 },
incomingCallText: {
marginTop: 8,
textAlign: 'center',
},
bottomContainer: { flex: 1, justifyContent: 'center' },
incomingCallControls: {
justifyContent: 'center',
},
});