ReactionBar.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react';
  2. import { View, TouchableOpacity, Text, StyleSheet, Dimensions } from 'react-native';
  3. import Animated, { FadeIn, FadeOut } from 'react-native-reanimated';
  4. import { MaterialCommunityIcons } from '@expo/vector-icons';
  5. import { Colors } from 'src/theme';
  6. interface MessagePosition {
  7. x: number;
  8. y: number;
  9. isMine: boolean;
  10. width: number;
  11. height: number;
  12. }
  13. interface ReactionBarProps {
  14. messagePosition: MessagePosition | null;
  15. selectedMessage: any;
  16. reactionEmojis: string[];
  17. handleReactionPress: (emoji: string, messageId: number) => void;
  18. openEmojiSelector: () => void;
  19. }
  20. const ReactionBar: React.FC<ReactionBarProps> = ({
  21. messagePosition,
  22. selectedMessage,
  23. reactionEmojis,
  24. handleReactionPress,
  25. openEmojiSelector
  26. }) =>
  27. selectedMessage &&
  28. messagePosition && (
  29. <Animated.View
  30. entering={FadeIn}
  31. exiting={FadeOut}
  32. style={[
  33. styles.reactionBar,
  34. {
  35. top: messagePosition.y - 50, // - reaction bar height
  36. left: messagePosition.isMine
  37. ? Dimensions.get('window').width - Dimensions.get('window').width * 0.75 - 8 // reaction bar width
  38. : messagePosition.x
  39. }
  40. ]}
  41. >
  42. {reactionEmojis.map((emoji) => (
  43. <TouchableOpacity
  44. key={emoji}
  45. onPress={() => handleReactionPress(emoji, selectedMessage?.currentMessage?._id)}
  46. >
  47. <Text style={styles.reactionEmoji}>{emoji}</Text>
  48. </TouchableOpacity>
  49. ))}
  50. <TouchableOpacity onPress={() => openEmojiSelector()} style={styles.addReactionButton}>
  51. <MaterialCommunityIcons name="plus" size={28} color={Colors.LIGHT_GRAY} />
  52. </TouchableOpacity>
  53. </Animated.View>
  54. );
  55. const styles = StyleSheet.create({
  56. reactionBar: {
  57. position: 'absolute',
  58. width: Dimensions.get('window').width * 0.75,
  59. flexDirection: 'row',
  60. backgroundColor: 'rgba(255, 255, 255, 1)',
  61. justifyContent: 'space-between',
  62. alignItems: 'center',
  63. borderRadius: 20,
  64. padding: 5,
  65. paddingHorizontal: 12,
  66. shadowColor: '#000',
  67. shadowOpacity: 0.3,
  68. shadowOffset: { width: 0, height: 2 },
  69. shadowRadius: 5,
  70. elevation: 5
  71. },
  72. reactionEmoji: {
  73. fontSize: 28
  74. },
  75. addReactionButton: {
  76. alignItems: 'center',
  77. justifyContent: 'center',
  78. backgroundColor: Colors.FILL_LIGHT,
  79. borderRadius: 15,
  80. borderWidth: 1,
  81. borderColor: Colors.LIGHT_GRAY,
  82. width: 30,
  83. height: 30
  84. }
  85. });
  86. export default ReactionBar;