-
Notifications
You must be signed in to change notification settings - Fork 3k
/
VideoChatButtonAndMenu.js
executable file
·159 lines (145 loc) · 5.44 KB
/
VideoChatButtonAndMenu.js
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
import _ from 'underscore';
import React, {Component} from 'react';
import {
View, Pressable, Dimensions, Linking,
} from 'react-native';
import PropTypes from 'prop-types';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Popover from './Popover';
import MenuItem from './MenuItem';
import ZoomIcon from '../../assets/images/zoom-icon.svg';
import GoogleMeetIcon from '../../assets/images/google-meet.svg';
import CONST from '../CONST';
import styles from '../styles/styles';
import themeColors from '../styles/themes/default';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import Tooltip from './Tooltip';
const propTypes = {
...withLocalizePropTypes,
...windowDimensionsPropTypes,
isConcierge: PropTypes.bool,
};
const defaultProps = {
isConcierge: false,
};
class VideoChatButtonAndMenu extends Component {
constructor(props) {
super(props);
this.dimensionsEventListener = null;
this.toggleVideoChatMenu = this.toggleVideoChatMenu.bind(this);
this.measureVideoChatIconPosition = this.measureVideoChatIconPosition.bind(this);
this.videoChatIconWrapper = null;
this.menuItemData = _.map([
{
icon: ZoomIcon,
text: props.translate('videoChatButtonAndMenu.zoom'),
onPress: () => Linking.openURL(CONST.NEW_ZOOM_MEETING_URL),
},
{
icon: GoogleMeetIcon,
text: props.translate('videoChatButtonAndMenu.googleMeet'),
onPress: () => Linking.openURL(CONST.NEW_GOOGLE_MEET_MEETING_URL),
},
], item => ({
...item,
onPress: () => {
item.onPress();
this.toggleVideoChatMenu();
},
}));
this.state = {
isVideoChatMenuActive: false,
videoChatIconPosition: {x: 0, y: 0},
};
}
componentDidMount() {
this.dimensionsEventListener = Dimensions.addEventListener('change', this.measureVideoChatIconPosition);
}
componentWillUnmount() {
if (!this.dimensionsEventListener) {
return;
}
this.dimensionsEventListener.remove();
}
/**
* Toggles the state variable isVideoChatMenuActive
*/
toggleVideoChatMenu() {
this.setState(prevState => ({
isVideoChatMenuActive: !prevState.isVideoChatMenuActive,
}));
}
/**
* This gets called onLayout to find the cooridnates of the wrapper for the video chat button.
*/
measureVideoChatIconPosition() {
if (!this.videoChatIconWrapper) {
return;
}
this.videoChatIconWrapper.measureInWindow((x, y) => this.setState({
videoChatIconPosition: {x, y},
}));
}
render() {
return (
<>
<View
ref={el => this.videoChatIconWrapper = el}
onLayout={this.measureVideoChatIconPosition}
>
<Tooltip text={this.props.translate('videoChatButtonAndMenu.tooltip')}>
<Pressable
onPress={() => {
// If this is the Concierge chat, we'll open the modal for requesting a setup call instead
if (this.props.isConcierge) {
Navigation.navigate(ROUTES.getRequestCallRoute(CONST.GUIDES_CALL_TASK_IDS.CONCIERGE_DM));
return;
}
this.toggleVideoChatMenu();
}}
style={[styles.touchableButtonImage, styles.mr0]}
>
<Icon
src={Expensicons.Phone}
fill={(this.props.isConcierge || this.state.isVideoChatMenuActive)
? themeColors.heading
: themeColors.icon}
/>
</Pressable>
</Tooltip>
</View>
<Popover
onClose={this.toggleVideoChatMenu}
isVisible={this.state.isVideoChatMenuActive}
anchorPosition={{
left: this.state.videoChatIconPosition.x - 150,
top: this.state.videoChatIconPosition.y + 40,
}}
animationIn="fadeInDown"
animationOut="fadeOutUp"
>
{_.map(this.menuItemData, ({icon, text, onPress}) => (
<MenuItem
wrapperStyle={styles.mr3}
key={text}
icon={icon}
title={text}
onPress={onPress}
/>
))}
</Popover>
</>
);
}
}
VideoChatButtonAndMenu.propTypes = propTypes;
VideoChatButtonAndMenu.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withLocalize,
)(VideoChatButtonAndMenu);