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

ReactionButton.tsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React, { useCallback } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { ColorValue, GestureResponderEvent, Text, TouchableHighlight, ViewStyle } from 'react-native';
  4. import { useDispatch } from 'react-redux';
  5. import { createReactionMenuEvent } from '../../../analytics/AnalyticsEvents';
  6. import { sendAnalytics } from '../../../analytics/functions';
  7. import { translate } from '../../../base/i18n/functions';
  8. import { StyleType } from '../../../base/styles/functions.native';
  9. import { addReactionToBuffer } from '../../actions.any';
  10. import { REACTIONS } from '../../constants';
  11. interface IReactionStyles {
  12. /**
  13. * Style for text container. Used on raise hand button.
  14. */
  15. container?: StyleType;
  16. /**
  17. * Style for the emoji text on the button.
  18. */
  19. emoji: StyleType;
  20. /**
  21. * Style for the gif button.
  22. */
  23. gifButton: StyleType;
  24. /**
  25. * Style for the button.
  26. */
  27. style: StyleType;
  28. /**
  29. * Style for the label text on the button.
  30. */
  31. text?: StyleType;
  32. /**
  33. * Underlay color for the button.
  34. */
  35. underlayColor: ColorValue;
  36. }
  37. /**
  38. * The type of the React {@code Component} props of {@link ReactionButton}.
  39. */
  40. interface IProps extends WithTranslation {
  41. /**
  42. * Component children.
  43. */
  44. children?: React.ReactNode;
  45. /**
  46. * External click handler.
  47. */
  48. onClick?: (e?: GestureResponderEvent) => void;
  49. /**
  50. * The reaction to be sent.
  51. */
  52. reaction?: string;
  53. /**
  54. * Collection of styles for the button.
  55. */
  56. styles: IReactionStyles;
  57. }
  58. /**
  59. * An implementation of a button to send a reaction.
  60. *
  61. * @returns {ReactElement}
  62. */
  63. function ReactionButton({
  64. children,
  65. onClick,
  66. styles,
  67. reaction,
  68. t
  69. }: IProps) {
  70. const dispatch = useDispatch();
  71. const _onClick = useCallback(() => {
  72. if (reaction) {
  73. dispatch(addReactionToBuffer(reaction));
  74. sendAnalytics(createReactionMenuEvent(reaction));
  75. }
  76. }, [ reaction ]);
  77. return (
  78. <TouchableHighlight
  79. accessibilityLabel = { t(`toolbar.accessibilityLabel.${reaction}`) }
  80. accessibilityRole = 'button'
  81. onPress = { onClick || _onClick }
  82. style = { [ styles.style, children && styles?.gifButton ] as ViewStyle[] }
  83. underlayColor = { styles.underlayColor }>
  84. {children ?? <Text style = { styles.emoji }>{REACTIONS[reaction ?? ''].emoji}</Text>}
  85. </TouchableHighlight>
  86. );
  87. }
  88. export default translate(ReactionButton);