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

ReactionEmoji.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // @flow
  2. import React, { useEffect, useMemo, useRef, useState } from 'react';
  3. import { Animated } from 'react-native';
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  6. import { removeReaction } from '../../actions.any';
  7. import { REACTIONS, type ReactionEmojiProps } from '../../constants';
  8. type Props = ReactionEmojiProps & {
  9. /**
  10. * Index of reaction on the queue.
  11. * Used to differentiate between first and other animations.
  12. */
  13. index: number
  14. };
  15. /**
  16. * Animated reaction emoji.
  17. *
  18. * @returns {ReactElement}
  19. */
  20. function ReactionEmoji({ reaction, uid, index }: Props) {
  21. const _styles = useSelector(state => ColorSchemeRegistry.get(state, 'Toolbox'));
  22. const _height = useSelector(state => state['features/base/responsive-ui'].clientHeight);
  23. const dispatch = useDispatch();
  24. const animationVal = useRef(new Animated.Value(0)).current;
  25. const vh = useState(_height / 100)[0];
  26. const randomInt = (min, max) => Math.floor((Math.random() * (max - min + 1)) + min);
  27. const animationIndex = useMemo(() => index % 21, [ index ]);
  28. const coordinates = useState({
  29. topX: animationIndex === 0 ? 40 : randomInt(-100, 100),
  30. topY: animationIndex === 0 ? -70 : randomInt(-65, -75),
  31. bottomX: animationIndex === 0 ? 140 : randomInt(150, 200),
  32. bottomY: animationIndex === 0 ? -50 : randomInt(-40, -50)
  33. })[0];
  34. useEffect(() => {
  35. setTimeout(() => dispatch(removeReaction(uid)), 5000);
  36. }, []);
  37. useEffect(() => {
  38. Animated.timing(
  39. animationVal,
  40. {
  41. toValue: 1,
  42. duration: 5000,
  43. useNativeDriver: true
  44. }
  45. ).start();
  46. }, [ animationVal ]);
  47. return (
  48. <Animated.Text
  49. style = {{
  50. ..._styles.emojiAnimation,
  51. transform: [
  52. { translateY: animationVal.interpolate({
  53. inputRange: [ 0, 0.70, 0.75, 1 ],
  54. // $FlowExpectedError
  55. outputRange: [ 0, coordinates.topY * vh, coordinates.topY * vh, coordinates.bottomY * vh ]
  56. })
  57. }, {
  58. translateX: animationVal.interpolate({
  59. inputRange: [ 0, 0.70, 0.75, 1 ],
  60. // $FlowExpectedError
  61. outputRange: [ 0, coordinates.topX, coordinates.topX,
  62. coordinates.topX < 0 ? -coordinates.bottomX : coordinates.bottomX ]
  63. })
  64. }, {
  65. scale: animationVal.interpolate({
  66. inputRange: [ 0, 0.70, 0.75, 1 ],
  67. // $FlowExpectedError
  68. outputRange: [ 0.6, 1.5, 1.5, 1 ]
  69. })
  70. }
  71. ],
  72. opacity: animationVal.interpolate({
  73. inputRange: [ 0, 0.7, 0.75, 1 ],
  74. // $FlowExpectedError
  75. outputRange: [ 1, 1, 1, 0 ]
  76. })
  77. }}>
  78. {REACTIONS[reaction].emoji}
  79. </Animated.Text>
  80. );
  81. }
  82. export default ReactionEmoji;