2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
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';
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
import EmojiPicker from '../../containers/EmojiPicker';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { isAndroid } from '../../utils/deviceInfo';
|
2021-02-19 18:05:47 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2021-12-02 02:52:17 +00:00
|
|
|
interface IRoomReactionPickerProps {
|
|
|
|
baseUrl: string;
|
|
|
|
message: {
|
|
|
|
id: string;
|
|
|
|
};
|
|
|
|
show: boolean;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
reactionClose(): void;
|
|
|
|
onEmojiSelected(shortname: string, messageId: string): void;
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
2019-01-29 19:52:56 +00:00
|
|
|
const margin = isAndroid ? 40 : 20;
|
2019-11-25 20:01:17 +00:00
|
|
|
const maxSize = 400;
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2021-12-02 02:52:17 +00:00
|
|
|
class ReactionPicker extends React.Component<IRoomReactionPickerProps, any> {
|
|
|
|
shouldComponentUpdate(nextProps: IRoomReactionPickerProps) {
|
2020-06-17 17:35:58 +00:00
|
|
|
const { show, width, height } = this.props;
|
|
|
|
return nextProps.show !== show || width !== nextProps.width || height !== nextProps.height;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 02:52:17 +00:00
|
|
|
onEmojiSelected = (emoji: string, shortname: string) => {
|
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-09-16 20:26:32 +00:00
|
|
|
const { onEmojiSelected, message } = this.props;
|
|
|
|
onEmojiSelected(shortname || emoji, message.id);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-01-30 19:48:26 +00:00
|
|
|
|
|
|
|
render() {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { width, height, show, baseUrl, reactionClose, isMasterDetail, theme } = this.props;
|
2018-03-02 21:31:44 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
let widthStyle = width - margin;
|
2021-09-13 20:41:05 +00:00
|
|
|
let heightStyle = Math.min(width, height) - margin * 2;
|
2020-06-15 14:00:46 +00:00
|
|
|
|
|
|
|
if (isMasterDetail) {
|
2019-11-25 20:01:17 +00:00
|
|
|
widthStyle = maxSize;
|
|
|
|
heightStyle = maxSize;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
return show ? (
|
|
|
|
<Modal
|
|
|
|
isVisible={show}
|
|
|
|
style={{ alignItems: 'center' }}
|
|
|
|
onBackdropPress={reactionClose}
|
|
|
|
onBackButtonPress={reactionClose}
|
|
|
|
animationIn='fadeIn'
|
|
|
|
animationOut='fadeOut'
|
|
|
|
backdropOpacity={themes[theme].backdropOpacity}>
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.reactionPickerContainer,
|
|
|
|
{
|
|
|
|
width: widthStyle,
|
|
|
|
height: heightStyle
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
testID='reaction-picker'>
|
2021-12-02 02:52:17 +00:00
|
|
|
<EmojiPicker onEmojiSelected={this.onEmojiSelected} baseUrl={baseUrl} />
|
2021-09-13 20:41:05 +00:00
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
) : null;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2021-12-02 02:52:17 +00:00
|
|
|
const mapStateToProps = (state: any) => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
baseUrl: state.server.server,
|
|
|
|
isMasterDetail: state.app.isMasterDetail
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2021-12-07 04:18:58 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ReactionPicker)) as any;
|