You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReactionButton.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableHighlight } from 'react-native';
  4. import { useDispatch } from 'react-redux';
  5. import { createReactionMenuEvent, sendAnalytics } from '../../../analytics';
  6. import { translate } from '../../../base/i18n';
  7. import type { StyleType } from '../../../base/styles';
  8. import { addReactionToBuffer } from '../../actions.any';
  9. import { REACTIONS } from '../../constants';
  10. export type ReactionStyles = {
  11. /**
  12. * Style for the button.
  13. */
  14. style: StyleType,
  15. /**
  16. * Underlay color for the button.
  17. */
  18. underlayColor: StyleType,
  19. /**
  20. * Style for the emoji text on the button.
  21. */
  22. emoji: StyleType,
  23. /**
  24. * Style for the label text on the button.
  25. */
  26. text?: StyleType,
  27. /**
  28. * Style for text container. Used on raise hand button.
  29. */
  30. container?: StyleType
  31. }
  32. /**
  33. * The type of the React {@code Component} props of {@link ReactionButton}.
  34. */
  35. type Props = {
  36. /**
  37. * Collection of styles for the button.
  38. */
  39. styles: ReactionStyles,
  40. /**
  41. * The reaction to be sent
  42. */
  43. reaction: string,
  44. /**
  45. * Invoked to obtain translated strings.
  46. */
  47. t: Function
  48. };
  49. /**
  50. * An implementation of a button to send a reaction.
  51. *
  52. * @returns {ReactElement}
  53. */
  54. function ReactionButton({
  55. styles,
  56. reaction,
  57. t
  58. }: Props) {
  59. const dispatch = useDispatch();
  60. /**
  61. * Handles clicking / pressing the button.
  62. *
  63. * @returns {void}
  64. */
  65. function _onClick() {
  66. dispatch(addReactionToBuffer(reaction));
  67. sendAnalytics(createReactionMenuEvent(reaction));
  68. }
  69. return (
  70. <TouchableHighlight
  71. accessibilityLabel = { t(`toolbar.accessibilityLabel.${reaction}`) }
  72. accessibilityRole = 'button'
  73. onPress = { _onClick }
  74. style = { styles.style }
  75. underlayColor = { styles.underlayColor }>
  76. <Text style = { styles.emoji }>{REACTIONS[reaction].emoji}</Text>
  77. </TouchableHighlight>
  78. );
  79. }
  80. export default translate(ReactionButton);