|
| 1 | +import React from 'react'; |
| 2 | +import { StyleSheet, Text, View } from 'react-native'; |
| 3 | +import Touchable from 'react-native-platform-touchable'; |
| 4 | + |
| 5 | +import { useAppSelector } from '../lib/hooks'; |
| 6 | +import { useTheme } from '../theme'; |
| 7 | +import sharedStyles from '../views/Styles'; |
| 8 | +import { CustomIcon } from './CustomIcon'; |
| 9 | +import { BUTTON_HIT_SLOP } from './message/utils'; |
| 10 | +import AvatarContainer from './Avatar'; |
| 11 | +import StatusContainer from './Status'; |
| 12 | +import DotsLoader from './DotsLoader'; |
| 13 | + |
| 14 | +type TCallHeader = { |
| 15 | + mic: boolean; |
| 16 | + cam: boolean; |
| 17 | + setCam: Function; |
| 18 | + setMic: Function; |
| 19 | + title: string; |
| 20 | + avatar: string; |
| 21 | + uid: string; |
| 22 | + name: string; |
| 23 | + direct: boolean; |
| 24 | +}; |
| 25 | + |
| 26 | +export const CallHeader = ({ mic, cam, setCam, setMic, title, avatar, uid, name, direct }: TCallHeader): React.ReactElement => { |
| 27 | + const style = useStyle(); |
| 28 | + const { colors } = useTheme(); |
| 29 | + const calling = useAppSelector(state => state.videoConf.calling); |
| 30 | + |
| 31 | + const handleColors = (enabled: boolean) => { |
| 32 | + if (calling) { |
| 33 | + if (enabled) return { button: colors.conferenceCallCallBackButton, icon: colors.gray300 }; |
| 34 | + return { button: 'transparent', icon: colors.gray100 }; |
| 35 | + } |
| 36 | + if (enabled) return { button: colors.conferenceCallEnabledIconBackground, icon: colors.conferenceCallEnabledIcon }; |
| 37 | + return { button: 'transparent', icon: colors.conferenceCallDisabledIcon }; |
| 38 | + }; |
| 39 | + |
| 40 | + return ( |
| 41 | + <View> |
| 42 | + <View style={style.actionSheetHeader}> |
| 43 | + <View style={style.rowContainer}> |
| 44 | + <Text style={style.actionSheetHeaderTitle}>{title}</Text> |
| 45 | + {calling && direct ? <DotsLoader /> : null} |
| 46 | + </View> |
| 47 | + <View style={style.actionSheetHeaderButtons}> |
| 48 | + <Touchable |
| 49 | + onPress={() => setCam(!cam)} |
| 50 | + style={[style.iconCallContainerRight, { backgroundColor: handleColors(cam).button }]} |
| 51 | + hitSlop={BUTTON_HIT_SLOP} |
| 52 | + disabled={calling} |
| 53 | + > |
| 54 | + <CustomIcon name={cam ? 'camera' : 'camera-disabled'} size={24} color={handleColors(cam).icon} /> |
| 55 | + </Touchable> |
| 56 | + <Touchable |
| 57 | + onPress={() => setMic(!mic)} |
| 58 | + style={[style.iconCallContainer, { backgroundColor: handleColors(mic).button }]} |
| 59 | + hitSlop={BUTTON_HIT_SLOP} |
| 60 | + disabled={calling} |
| 61 | + > |
| 62 | + <CustomIcon name={mic ? 'microphone' : 'microphone-disabled'} size={24} color={handleColors(mic).icon} /> |
| 63 | + </Touchable> |
| 64 | + </View> |
| 65 | + </View> |
| 66 | + <View style={style.actionSheetUsernameContainer}> |
| 67 | + <AvatarContainer text={avatar} size={36} /> |
| 68 | + {direct ? <StatusContainer size={16} id={uid} style={style.statusContainerMargin} /> : null} |
| 69 | + <Text style={{ ...style.actionSheetUsername, marginLeft: !direct ? 8 : 0 }} numberOfLines={1}> |
| 70 | + {name} |
| 71 | + </Text> |
| 72 | + </View> |
| 73 | + </View> |
| 74 | + ); |
| 75 | +}; |
| 76 | + |
| 77 | +function useStyle() { |
| 78 | + const { colors } = useTheme(); |
| 79 | + const style = StyleSheet.create({ |
| 80 | + actionSheetHeader: { flexDirection: 'row', alignItems: 'center' }, |
| 81 | + actionSheetHeaderTitle: { |
| 82 | + fontSize: 14, |
| 83 | + ...sharedStyles.textBold, |
| 84 | + color: colors.n900 |
| 85 | + }, |
| 86 | + actionSheetHeaderButtons: { flex: 1, alignItems: 'center', flexDirection: 'row', justifyContent: 'flex-end' }, |
| 87 | + iconCallContainer: { |
| 88 | + padding: 6, |
| 89 | + borderRadius: 4 |
| 90 | + }, |
| 91 | + iconCallContainerRight: { |
| 92 | + padding: 6, |
| 93 | + borderRadius: 4, |
| 94 | + marginRight: 6 |
| 95 | + }, |
| 96 | + actionSheetUsernameContainer: { flexDirection: 'row', paddingTop: 8, alignItems: 'center' }, |
| 97 | + actionSheetUsername: { |
| 98 | + fontSize: 16, |
| 99 | + ...sharedStyles.textBold, |
| 100 | + color: colors.passcodePrimary, |
| 101 | + flexShrink: 1 |
| 102 | + }, |
| 103 | + rowContainer: { flexDirection: 'row' }, |
| 104 | + statusContainerMargin: { marginLeft: 8, marginRight: 6 } |
| 105 | + }); |
| 106 | + return style; |
| 107 | +} |
0 commit comments