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';
|
|
|
|
import { responsive } from 'react-native-responsive-ui';
|
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';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { withSplit } from '../../split';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2019-01-29 19:52:56 +00:00
|
|
|
const margin = isAndroid ? 40 : 20;
|
2019-12-11 23:01:12 +00:00
|
|
|
const maxSize = 400;
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2019-08-20 19:24:22 +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,
|
2018-01-30 19:48:26 +00:00
|
|
|
window: PropTypes.any,
|
2019-10-07 20:56:30 +00:00
|
|
|
message: PropTypes.object,
|
|
|
|
show: PropTypes.bool,
|
|
|
|
reactionClose: PropTypes.func,
|
2019-12-11 23:01:12 +00:00
|
|
|
onEmojiSelected: PropTypes.func,
|
|
|
|
split: PropTypes.bool
|
2018-01-30 19:48:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2019-12-11 23:01:12 +00:00
|
|
|
const { show, window, split } = this.props;
|
|
|
|
return nextProps.show !== show || window.width !== nextProps.window.width || nextProps.split !== split;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 23:01:12 +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-10-07 20:56:30 +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 {
|
2019-12-11 23:01:12 +00:00
|
|
|
window: { width, height }, show, baseUrl, reactionClose, split
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
2018-03-02 21:31:44 +00:00
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
let widthStyle = width - margin;
|
|
|
|
let heightStyle = Math.min(width, height) - (margin * 2);
|
|
|
|
if (split) {
|
|
|
|
widthStyle = maxSize;
|
|
|
|
heightStyle = maxSize;
|
|
|
|
}
|
|
|
|
|
2019-10-07 20:56:30 +00:00
|
|
|
return (show
|
2018-09-25 19:28:42 +00:00
|
|
|
? (
|
|
|
|
<Modal
|
2019-10-07 20:56:30 +00:00
|
|
|
isVisible={show}
|
2018-09-25 19:28:42 +00:00
|
|
|
style={{ alignItems: 'center' }}
|
2019-10-07 20:56:30 +00:00
|
|
|
onBackdropPress={reactionClose}
|
|
|
|
onBackButtonPress={reactionClose}
|
2018-09-25 19:28:42 +00:00
|
|
|
animationIn='fadeIn'
|
|
|
|
animationOut='fadeOut'
|
2018-05-23 13:39:18 +00:00
|
|
|
>
|
2018-09-25 19:28:42 +00:00
|
|
|
<View
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[
|
|
|
|
styles.reactionPickerContainer,
|
|
|
|
{
|
|
|
|
width: widthStyle,
|
|
|
|
height: heightStyle
|
|
|
|
}
|
|
|
|
]}
|
2018-09-25 19:28:42 +00:00
|
|
|
testID='reaction-picker'
|
|
|
|
>
|
|
|
|
<EmojiPicker
|
2019-12-11 23:01:12 +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-20 19:24:22 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
|
|
|
|
});
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
export default responsive(connect(mapStateToProps)(withSplit(ReactionPicker)));
|