vn-verdnaturachat/app/views/RoomView/ReactionPicker.js

77 lines
2.4 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 { toggleReactionPicker as toggleReactionPickerAction } from '../../actions/messages';
import styles from './styles';
2019-01-29 19:52:56 +00:00
import { isAndroid } from '../../utils/deviceInfo';
2019-01-29 19:52:56 +00:00
const margin = isAndroid ? 40 : 20;
const tabEmojiStyle = { fontSize: 15 };
@connect(state => ({
showReactionPicker: state.messages.showReactionPicker,
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
}), dispatch => ({
toggleReactionPicker: message => dispatch(toggleReactionPickerAction(message))
}))
@responsive
export default class ReactionPicker extends React.Component {
static propTypes = {
baseUrl: PropTypes.string.isRequired,
window: PropTypes.any,
showReactionPicker: PropTypes.bool,
toggleReactionPicker: PropTypes.func,
onEmojiSelected: PropTypes.func
};
shouldComponentUpdate(nextProps) {
const { showReactionPicker, window } = this.props;
return nextProps.showReactionPicker !== showReactionPicker || 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
const { onEmojiSelected } = this.props;
onEmojiSelected(shortname || emoji);
}
render() {
const {
window: { width, height }, showReactionPicker, baseUrl, toggleReactionPicker
} = this.props;
2018-03-02 21:31:44 +00:00
return (showReactionPicker
? (
<Modal
isVisible={showReactionPicker}
style={{ alignItems: 'center' }}
onBackdropPress={() => toggleReactionPicker()}
onBackButtonPress={() => toggleReactionPicker()}
animationIn='fadeIn'
animationOut='fadeOut'
2018-05-23 13:39:18 +00:00
>
<View
style={[styles.reactionPickerContainer, { width: width - margin, height: Math.min(width, height) - (margin * 2) }]}
testID='reaction-picker'
>
<EmojiPicker
tabEmojiStyle={tabEmojiStyle}
width={Math.min(width, height) - margin}
onEmojiSelected={(emoji, shortname) => this.onEmojiSelected(emoji, shortname)}
baseUrl={baseUrl}
/>
</View>
</Modal>
)
: null
);
}
}