PinMessage.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. <TextView style={styles.textMessage} numberOfLines={15}>{item.pinContent}</TextView>
  42. }
  43. </View>
  44. )
  45. }
  46. export default PinMessage;
  47. const styles = StyleSheet.create({
  48. pinMessageView: {
  49. top: 180,
  50. left: 16,
  51. right: 16,
  52. zIndex: 10,
  53. maxHeight: $vh(60),
  54. overflow: "hidden",
  55. position: 'absolute',
  56. },
  57. messageCard: {
  58. marginBottom: 16,
  59. maxHeight: $vw(60),
  60. overflow: "hidden",
  61. borderRadius: 6,
  62. backgroundColor: colorLight,
  63. ...ElevationObject(3)
  64. },
  65. marquee: {
  66. flex: 1,
  67. overflow: "hidden",
  68. ...$padding(12, 16)
  69. },
  70. textTitle: {
  71. color: textPrimary,
  72. fontSize: 16,
  73. fontWeight: "bold"
  74. },
  75. fixedTitle: {
  76. flex: 1,
  77. color: textPrimary,
  78. fontSize: 16,
  79. fontWeight: "bold",
  80. ...$padding(12, 16)
  81. },
  82. textMessage: {
  83. color: textSecondary,
  84. paddingLeft: 16,
  85. paddingRight: 16,
  86. paddingBottom: 16,
  87. fontSize: 14
  88. }
  89. })