2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { View } from 'react-native';
|
2018-01-30 19:48:26 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import Modal from 'react-native-modal';
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
import EmojiPicker from '../../containers/EmojiPicker';
|
|
|
|
import styles from './styles';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { isAndroid } from '../../utils/deviceInfo';
|
2021-02-19 18:05:47 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2019-01-29 19:52:56 +00:00
|
|
|
const margin = isAndroid ? 40 : 20;
|
2019-11-25 20:01:17 +00:00
|
|
|
const maxSize = 400;
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class ReactionPicker extends React.Component {
|
2018-01-30 19:48:26 +00:00
|
|
|
static propTypes = {
|
2018-09-11 16:32:52 +00:00
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2019-09-16 20:26:32 +00:00
|
|
|
message: PropTypes.object,
|
|
|
|
show: PropTypes.bool,
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: PropTypes.bool,
|
2019-09-16 20:26:32 +00:00
|
|
|
reactionClose: PropTypes.func,
|
2020-06-17 17:35:58 +00:00
|
|
|
onEmojiSelected: PropTypes.func,
|
|
|
|
width: PropTypes.number,
|
2021-02-19 18:05:47 +00:00
|
|
|
height: PropTypes.number,
|
|
|
|
theme: PropTypes.string
|
2018-01-30 19:48:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2020-06-17 17:35:58 +00:00
|
|
|
const { show, width, height } = this.props;
|
|
|
|
return nextProps.show !== show || width !== nextProps.width || height !== nextProps.height;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
onEmojiSelected = (emoji, shortname) => {
|
2018-01-30 19:48:26 +00:00
|
|
|
// standard emojis: `emoji` is unicode and `shortname` is :joy:
|
|
|
|
// custom emojis: only `emoji` is returned with shortname type (:joy:)
|
|
|
|
// to set reactions, we need shortname type
|
2019-09-16 20:26:32 +00:00
|
|
|
const { onEmojiSelected, message } = this.props;
|
|
|
|
onEmojiSelected(shortname || emoji, message.id);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
2021-02-19 18:05:47 +00:00
|
|
|
width, height, show, baseUrl, reactionClose, isMasterDetail, theme
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
2018-03-02 21:31:44 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
let widthStyle = width - margin;
|
|
|
|
let heightStyle = Math.min(width, height) - (margin * 2);
|
2020-06-15 14:00:46 +00:00
|
|
|
|
|
|
|
if (isMasterDetail) {
|
2019-11-25 20:01:17 +00:00
|
|
|
widthStyle = maxSize;
|
|
|
|
heightStyle = maxSize;
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
return (show
|
2018-09-25 19:28:42 +00:00
|
|
|
? (
|
|
|
|
<Modal
|
2019-09-16 20:26:32 +00:00
|
|
|
isVisible={show}
|
2018-09-25 19:28:42 +00:00
|
|
|
style={{ alignItems: 'center' }}
|
2019-09-16 20:26:32 +00:00
|
|
|
onBackdropPress={reactionClose}
|
|
|
|
onBackButtonPress={reactionClose}
|
2018-09-25 19:28:42 +00:00
|
|
|
animationIn='fadeIn'
|
|
|
|
animationOut='fadeOut'
|
2021-02-19 18:05:47 +00:00
|
|
|
backdropOpacity={themes[theme].backdropOpacity}
|
2018-05-23 13:39:18 +00:00
|
|
|
>
|
2018-09-25 19:28:42 +00:00
|
|
|
<View
|
2019-11-25 20:01:17 +00:00
|
|
|
style={[
|
|
|
|
styles.reactionPickerContainer,
|
|
|
|
{
|
|
|
|
width: widthStyle,
|
|
|
|
height: heightStyle
|
|
|
|
}
|
|
|
|
]}
|
2018-09-25 19:28:42 +00:00
|
|
|
testID='reaction-picker'
|
|
|
|
>
|
|
|
|
<EmojiPicker
|
2019-11-25 20:01:17 +00:00
|
|
|
// tabEmojiStyle={tabEmojiStyle}
|
|
|
|
onEmojiSelected={this.onEmojiSelected}
|
2018-09-25 19:28:42 +00:00
|
|
|
baseUrl={baseUrl}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
)
|
|
|
|
: null
|
2018-01-30 19:48:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
baseUrl: state.server.server,
|
|
|
|
isMasterDetail: state.app.isMasterDetail
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2021-02-19 18:05:47 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ReactionPicker));
|