2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { View, Platform } 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 { toggleReactionPicker } from '../../actions/messages';
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const margin = Platform.OS === 'android' ? 40 : 20;
|
|
|
|
const tabEmojiStyle = { fontSize: 15 };
|
|
|
|
|
|
|
|
@connect(state => ({
|
|
|
|
showReactionPicker: state.messages.showReactionPicker
|
|
|
|
}), dispatch => ({
|
|
|
|
toggleReactionPicker: message => dispatch(toggleReactionPicker(message))
|
|
|
|
}))
|
|
|
|
@responsive
|
2018-02-08 14:08:50 +00:00
|
|
|
export default class ReactionPicker extends React.Component {
|
2018-01-30 19:48:26 +00:00
|
|
|
static propTypes = {
|
|
|
|
window: PropTypes.any,
|
|
|
|
showReactionPicker: PropTypes.bool,
|
|
|
|
toggleReactionPicker: PropTypes.func,
|
|
|
|
onEmojiSelected: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return nextProps.showReactionPicker !== this.props.showReactionPicker || this.props.window.width !== nextProps.window.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
this.props.onEmojiSelected(shortname || emoji);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-04-03 16:24:59 +00:00
|
|
|
const { window: { width, height }, showReactionPicker } = this.props;
|
2018-03-02 21:31:44 +00:00
|
|
|
|
|
|
|
return (showReactionPicker ?
|
2018-01-30 19:48:26 +00:00
|
|
|
<Modal
|
|
|
|
isVisible={this.props.showReactionPicker}
|
|
|
|
style={{ alignItems: 'center' }}
|
|
|
|
onBackdropPress={() => this.props.toggleReactionPicker()}
|
|
|
|
onBackButtonPress={() => this.props.toggleReactionPicker()}
|
|
|
|
animationIn='fadeIn'
|
|
|
|
animationOut='fadeOut'
|
|
|
|
>
|
|
|
|
<View style={[styles.reactionPickerContainer, { width: width - margin, height: Math.min(width, height) - (margin * 2) }]}>
|
|
|
|
<EmojiPicker
|
|
|
|
tabEmojiStyle={tabEmojiStyle}
|
|
|
|
width={Math.min(width, height) - margin}
|
|
|
|
onEmojiSelected={(emoji, shortname) => this.onEmojiSelected(emoji, shortname)}
|
|
|
|
/>
|
|
|
|
</View>
|
2018-03-02 21:31:44 +00:00
|
|
|
</Modal> : null
|
2018-01-30 19:48:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|