PinMessage.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React, { useEffect, useState } from 'react';
  2. import { ScrollView, StyleSheet, Text, View } from 'react-native';
  3. import { Marquee } from '@animatereactnative/marquee';
  4. import { ElevationObject } from '../../../components/Button';
  5. import TextView from '../../../components/TextView';
  6. const PinMessage = ({
  7. visible=false,
  8. messageList=[]
  9. }) => {
  10. if (visible)
  11. return (
  12. <View style={styles.pinMessageView}>
  13. { messageList.map((item, index) =>
  14. <Message key={index} item={item}/>
  15. )}
  16. </View>
  17. );
  18. else
  19. return <></>
  20. }
  21. const Message = ({item}) => {
  22. const [expand, setExpand] = useState(false)
  23. const max = ($width-32)/8;
  24. return (
  25. <View style={styles.messageCard}>
  26. <View style={ui.flexc}>
  27. { item.pinTitle?.length>max
  28. ? <Marquee style={styles.marquee} spacing={$vw(80)} speed={0.8}>
  29. <Text style={styles.textTitle} numberOfLines={1}>{item.pinTitle}</Text>
  30. </Marquee>
  31. : <Text style={styles.fixedTitle} numberOfLines={expand ? 5 : 1}>{item.pinTitle}</Text>
  32. }
  33. <FontAwesome6
  34. style={$padding(12, 16, 12, 0)}
  35. name={expand == true ? "chevron-up" : "chevron-down"}
  36. size={16}
  37. color={colorCancel}
  38. onPress={() => setExpand(!expand)}/>
  39. </View>
  40. { expand &&
  41. <ScrollView>
  42. <TextView style={styles.textMessage} numberOfLines={15}>{item.pinContent}</TextView>
  43. </ScrollView>
  44. }
  45. </View>
  46. )
  47. }
  48. export default PinMessage;
  49. const styles = StyleSheet.create({
  50. pinMessageView: {
  51. top: 180,
  52. left: 16,
  53. right: 16,
  54. zIndex: 10,
  55. maxHeight: $vh(60),
  56. overflow: "hidden",
  57. position: 'absolute',
  58. },
  59. messageCard: {
  60. marginBottom: 16,
  61. maxHeight: $vw(50),
  62. overflow: "hidden",
  63. borderRadius: 6,
  64. backgroundColor: colorLight,
  65. ...ElevationObject(3)
  66. },
  67. marquee: {
  68. flex: 1,
  69. overflow: "hidden",
  70. ...$padding(12, 16)
  71. },
  72. textTitle: {
  73. color: textPrimary,
  74. fontSize: 16,
  75. fontWeight: "bold"
  76. },
  77. fixedTitle: {
  78. flex: 1,
  79. color: textPrimary,
  80. fontSize: 16,
  81. fontWeight: "bold",
  82. ...$padding(12, 16)
  83. },
  84. textMessage: {
  85. color: textSecondary,
  86. paddingLeft: 16,
  87. paddingRight: 16,
  88. paddingBottom: 16,
  89. fontSize: 14
  90. }
  91. })