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';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2019-01-29 19:52:56 +00:00
|
|
|
const margin = isAndroid ? 40 : 20;
|
2018-01-30 19:48:26 +00:00
|
|
|
const tabEmojiStyle = { fontSize: 15 };
|
|
|
|
|
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,
|
2018-01-30 19:48:26 +00:00
|
|
|
window: PropTypes.any,
|
2019-09-16 20:26:32 +00:00
|
|
|
message: PropTypes.object,
|
|
|
|
show: PropTypes.bool,
|
|
|
|
reactionClose: PropTypes.func,
|
2018-01-30 19:48:26 +00:00
|
|
|
onEmojiSelected: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { show, window } = this.props;
|
|
|
|
return nextProps.show !== show || window.width !== nextProps.window.width;
|
2018-01-30 19:48:26 +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
|
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 {
|
2019-09-16 20:26:32 +00:00
|
|
|
window: { width, height }, show, baseUrl, reactionClose
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
2018-03-02 21:31:44 +00:00
|
|
|
|
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'
|
2018-05-23 13:39:18 +00:00
|
|
|
>
|
2018-09-25 19:28:42 +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
|
2018-01-30 19:48:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
|
|
|
|
});
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
export default responsive(connect(mapStateToProps)(ReactionPicker));
|