mattermost-mobile/app/components/reaction_picker/reaction_button.js
Andre Vasconcelos d03d504d00
MM-14038 Access recent reactions from the long press menu (#4058)
* WIP: Implementing quick reaction functionality

* Making closing animations smoother

- Added haptic feedback + timeouts for a smooth flow

* Fixing clipping of post options on android

* updating snapshots

* Refactoring code & fixing styles

- Fixed paddings element sizes to comply with design specs
- Replaced reaction image to one with a higher resolution
- Made sizes of emojis to be conditional on deviceWidth

* Apply suggestions from code review

* Adding component to avoid extra re-renders

* Refactoring function call in reaction_button

Am ashamed i didn't catch this before pushing the rest

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-01 12:56:49 -07:00

98 lines
2.6 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {
View,
TouchableWithoutFeedback,
} from 'react-native';
import Emoji from 'app/components/emoji';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import {hapticFeedback} from 'app/utils/general';
import {
LARGE_CONTAINER_SIZE,
LARGE_ICON_SIZE,
} from 'app/constants/reaction_picker';
export default class ReactionButton extends PureComponent {
static propTypes = {
addReaction: PropTypes.func.isRequired,
theme: PropTypes.object.isRequired,
emoji: PropTypes.string.isRequired,
iconSize: PropTypes.number,
containerSize: PropTypes.number,
}
static defaultProps = {
iconSize: LARGE_ICON_SIZE,
containerSize: LARGE_CONTAINER_SIZE,
};
constructor(props) {
super(props);
this.state = {
isSelected: false,
};
}
handlePress = () => {
hapticFeedback();
this.setState({isSelected: true}, () => {
this.props.addReaction(this.props.emoji);
});
}
render() {
const {
theme,
emoji,
iconSize,
containerSize,
} = this.props;
const style = getStyleSheet(theme);
return (
<TouchableWithoutFeedback
key={emoji}
onPress={this.handlePress}
>
<View
style={[
style.reactionContainer,
this.state.isSelected ? style.highlight : null,
{
width: containerSize,
height: containerSize,
},
]}
>
<Emoji
emojiName={emoji}
textStyle={style.emoji}
size={iconSize}
/>
</View>
</TouchableWithoutFeedback>
);
}
}
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
return {
emoji: {
color: '#000',
fontWeight: 'bold',
},
highlight: {
backgroundColor: changeOpacity(theme.linkColor, 0.1),
},
reactionContainer: {
backgroundColor: changeOpacity(theme.centerChannelColor, 0.04),
borderRadius: 4,
alignItems: 'center',
justifyContent: 'center',
},
};
});