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 1.9KB

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