Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ReactionButton.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // @flow
  2. import React, { useCallback } 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 gif button.
  13. */
  14. gifButton: StyleType,
  15. /**
  16. * Style for the button.
  17. */
  18. style: StyleType,
  19. /**
  20. * Underlay color for the button.
  21. */
  22. underlayColor: StyleType,
  23. /**
  24. * Style for the emoji text on the button.
  25. */
  26. emoji: StyleType,
  27. /**
  28. * Style for the label text on the button.
  29. */
  30. text?: StyleType,
  31. /**
  32. * Style for text container. Used on raise hand button.
  33. */
  34. container?: StyleType
  35. }
  36. /**
  37. * The type of the React {@code Component} props of {@link ReactionButton}.
  38. */
  39. type Props = {
  40. /**
  41. * Component children.
  42. */
  43. children?: ReactNode,
  44. /**
  45. * External click handler.
  46. */
  47. onClick?: Function,
  48. /**
  49. * Collection of styles for the button.
  50. */
  51. styles: ReactionStyles,
  52. /**
  53. * The reaction to be sent.
  54. */
  55. reaction: string,
  56. /**
  57. * Invoked to obtain translated strings.
  58. */
  59. t: Function
  60. };
  61. /**
  62. * An implementation of a button to send a reaction.
  63. *
  64. * @returns {ReactElement}
  65. */
  66. function ReactionButton({
  67. children,
  68. onClick,
  69. styles,
  70. reaction,
  71. t
  72. }: Props) {
  73. const dispatch = useDispatch();
  74. const _onClick = useCallback(() => {
  75. dispatch(addReactionToBuffer(reaction));
  76. sendAnalytics(createReactionMenuEvent(reaction));
  77. }, [ reaction ]);
  78. return (
  79. <TouchableHighlight
  80. accessibilityLabel = { t(`toolbar.accessibilityLabel.${reaction}`) }
  81. accessibilityRole = 'button'
  82. onPress = { onClick || _onClick }
  83. style = { [ styles.style, children && styles?.gifButton ] }
  84. underlayColor = { styles.underlayColor }>
  85. {children ?? <Text style = { styles.emoji }>{REACTIONS[reaction].emoji}</Text>}
  86. </TouchableHighlight>
  87. );
  88. }
  89. export default translate(ReactionButton);