您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReactionEmoji.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. outputRange: [ 0, coordinates.topY * vh, coordinates.topY * vh, coordinates.bottomY * vh ]
  55. })
  56. }, {
  57. translateX: animationVal.interpolate({
  58. inputRange: [ 0, 0.70, 0.75, 1 ],
  59. outputRange: [ 0, coordinates.topX, coordinates.topX,
  60. coordinates.topX < 0 ? -coordinates.bottomX : coordinates.bottomX ]
  61. })
  62. }, {
  63. scale: animationVal.interpolate({
  64. inputRange: [ 0, 0.70, 0.75, 1 ],
  65. outputRange: [ 0.6, 1.5, 1.5, 1 ]
  66. })
  67. }
  68. ],
  69. opacity: animationVal.interpolate({
  70. inputRange: [ 0, 0.7, 0.75, 1 ],
  71. outputRange: [ 1, 1, 1, 0 ]
  72. })
  73. }}>
  74. {REACTIONS[reaction].emoji}
  75. </Animated.Text>
  76. );
  77. }
  78. export default ReactionEmoji;