verdnatura-chat/app/views/RoomView/ReactionPicker.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
2019-01-29 19:52:56 +00:00
import { View } from 'react-native';
import { connect } from 'react-redux';
import Modal from 'react-native-modal';
import { responsive } from 'react-native-responsive-ui';
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';
2019-01-29 19:52:56 +00:00
const margin = isAndroid ? 40 : 20;
2019-12-11 23:01:12 +00:00
const maxSize = 400;
class ReactionPicker extends React.Component {
static propTypes = {
baseUrl: PropTypes.string.isRequired,
window: PropTypes.any,
message: PropTypes.object,
show: PropTypes.bool,
reactionClose: PropTypes.func,
2019-12-11 23:01:12 +00:00
onEmojiSelected: PropTypes.func,
split: PropTypes.bool
};
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;
}
2019-12-11 23:01:12 +00:00
onEmojiSelected = (emoji, shortname) => {
// 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
const { onEmojiSelected, message } = this.props;
onEmojiSelected(shortname || emoji, message.id);
}
render() {
const {
2019-12-11 23:01:12 +00:00
window: { width, height }, show, baseUrl, reactionClose, split
} = 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;
}
return (show
? (
<Modal
isVisible={show}
style={{ alignItems: 'center' }}
onBackdropPress={reactionClose}
onBackButtonPress={reactionClose}
animationIn='fadeIn'
animationOut='fadeOut'
2018-05-23 13:39:18 +00:00
>
<View
2019-12-11 23:01:12 +00:00
style={[
styles.reactionPickerContainer,
{
width: widthStyle,
height: heightStyle
}
]}
testID='reaction-picker'
>
<EmojiPicker
2019-12-11 23:01:12 +00:00
// tabEmojiStyle={tabEmojiStyle}
onEmojiSelected={this.onEmojiSelected}
baseUrl={baseUrl}
/>
</View>
</Modal>
)
: null
);
}
}
const mapStateToProps = state => ({
2020-02-19 19:43:47 +00:00
baseUrl: state.server.server
});
2019-12-11 23:01:12 +00:00
export default responsive(connect(mapStateToProps)(withSplit(ReactionPicker)));