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';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2022-03-02 14:18:01 +00:00
|
|
|
import { IApplicationState } from '../../definitions';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
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
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
interface IReactionPickerProps {
|
|
|
|
baseUrl: string;
|
|
|
|
message?: any;
|
|
|
|
show: boolean;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
reactionClose: () => void;
|
|
|
|
onEmojiSelected: Function; // TODO: properly type this
|
|
|
|
width: number;
|
|
|
|
height: number;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-03-02 14:18:01 +00:00
|
|
|
}
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
class ReactionPicker extends React.Component<IReactionPickerProps> {
|
|
|
|
shouldComponentUpdate(nextProps: IReactionPickerProps) {
|
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
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +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;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (message) {
|
|
|
|
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'>
|
|
|
|
<EmojiPicker
|
|
|
|
// tabEmojiStyle={tabEmojiStyle}
|
|
|
|
onEmojiSelected={this.onEmojiSelected}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
) : null;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
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-02-19 18:05:47 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ReactionPicker));
|