2021-07-13 06:50:08 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { Text, TouchableHighlight } from 'react-native';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
import { createReactionMenuEvent, sendAnalytics } from '../../../analytics';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import type { StyleType } from '../../../base/styles';
|
2021-07-20 11:31:49 +00:00
|
|
|
import { addReactionToBuffer } from '../../actions.any';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { REACTIONS } from '../../constants';
|
|
|
|
|
|
|
|
|
|
|
|
export type ReactionStyles = {
|
|
|
|
|
2022-03-30 13:54:03 +00:00
|
|
|
/**
|
|
|
|
* Style for the gif button.
|
|
|
|
*/
|
|
|
|
gifButton: StyleType,
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* Style for the button.
|
|
|
|
*/
|
|
|
|
style: StyleType,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Underlay color for the button.
|
|
|
|
*/
|
|
|
|
underlayColor: StyleType,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Style for the emoji text on the button.
|
|
|
|
*/
|
|
|
|
emoji: StyleType,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Style for the label text on the button.
|
|
|
|
*/
|
|
|
|
text?: StyleType,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Style for text container. Used on raise hand button.
|
|
|
|
*/
|
|
|
|
container?: StyleType
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link ReactionButton}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
2022-03-30 13:54:03 +00:00
|
|
|
/**
|
|
|
|
* Component children.
|
|
|
|
*/
|
|
|
|
children?: ReactNode,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External click handler.
|
|
|
|
*/
|
|
|
|
onClick?: Function,
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* Collection of styles for the button.
|
|
|
|
*/
|
|
|
|
styles: ReactionStyles,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The reaction to be sent.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
|
|
|
reaction: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of a button to send a reaction.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
function ReactionButton({
|
2022-03-30 13:54:03 +00:00
|
|
|
children,
|
|
|
|
onClick,
|
2021-07-13 06:50:08 +00:00
|
|
|
styles,
|
|
|
|
reaction,
|
|
|
|
t
|
|
|
|
}: Props) {
|
|
|
|
const dispatch = useDispatch();
|
2021-11-04 21:10:43 +00:00
|
|
|
const _onClick = useCallback(() => {
|
2021-07-20 11:31:49 +00:00
|
|
|
dispatch(addReactionToBuffer(reaction));
|
|
|
|
sendAnalytics(createReactionMenuEvent(reaction));
|
2021-11-04 21:10:43 +00:00
|
|
|
}, [ reaction ]);
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableHighlight
|
|
|
|
accessibilityLabel = { t(`toolbar.accessibilityLabel.${reaction}`) }
|
|
|
|
accessibilityRole = 'button'
|
2022-03-30 13:54:03 +00:00
|
|
|
onPress = { onClick || _onClick }
|
|
|
|
style = { [ styles.style, children && styles?.gifButton ] }
|
2021-07-13 06:50:08 +00:00
|
|
|
underlayColor = { styles.underlayColor }>
|
2022-03-30 13:54:03 +00:00
|
|
|
{children ?? <Text style = { styles.emoji }>{REACTIONS[reaction].emoji}</Text>}
|
2021-07-13 06:50:08 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(ReactionButton);
|