PinMessage.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. import MyModal from '../../../components/MyModal';
  7. import Swiper from 'react-native-swiper';
  8. import Dialog from '../../../components/Dialog';
  9. const PinMessage = ({
  10. messageList=[]
  11. }) => {
  12. const [visible, showDialog] = useState(false);
  13. useEffect(() => {
  14. if (messageList.length > 0) {
  15. showDialog(true)
  16. }
  17. }, [messageList])
  18. if (visible)
  19. return (
  20. <MyModal
  21. style={styles.noticeDialog}
  22. visible={visible}>
  23. <Swiper
  24. style={{height: $vh(50)}}
  25. loop={false}
  26. autoplay={false}
  27. //dotColor={"#ccc"}
  28. activeDotColor={colorAccent}
  29. removeClippedSubviews={false}
  30. decelerationRate={"fast"}
  31. automaticallyAdjustContentInsets={true}>
  32. { messageList.map((item, index) =>
  33. <NoticeView
  34. key={index}
  35. item={item}
  36. onClose={() => showDialog(false)}/>
  37. )}
  38. </Swiper>
  39. </MyModal>
  40. );
  41. else
  42. return <></>
  43. }
  44. const Message = ({item}) => {
  45. const [expand, setExpand] = useState(false)
  46. const max = ($width-32)/8;
  47. return (
  48. <View style={styles.messageCard}>
  49. <View style={ui.flexc}>
  50. { item.pinTitle?.length>max
  51. ? <Marquee style={styles.marquee} spacing={$vw(80)} speed={0.8}>
  52. <Text style={styles.textTitle} numberOfLines={1}>{item.pinTitle}</Text>
  53. </Marquee>
  54. : <Text style={styles.fixedTitle} numberOfLines={expand ? 5 : 1}>{item.pinTitle}</Text>
  55. }
  56. <FontAwesome6
  57. style={$padding(12, 16, 12, 0)}
  58. name={expand == true ? "chevron-up" : "chevron-down"}
  59. size={16}
  60. color={colorCancel}
  61. onPress={() => setExpand(!expand)}/>
  62. </View>
  63. { expand &&
  64. <ScrollView>
  65. <TextView style={styles.textMessage}>{item.pinContent}</TextView>
  66. </ScrollView>
  67. }
  68. </View>
  69. )
  70. }
  71. const NoticeView = ({item, onClose}) => {
  72. return (
  73. <View style={styles.notiveView}>
  74. <TextView style={styles.noticeTitle}>{item.pinTitle}</TextView>
  75. <View style={styles.closeIcon}>
  76. <MaterialIcons
  77. onPress={onClose}
  78. name="close"
  79. color="#ccc"
  80. size={24}/>
  81. </View>
  82. <ScrollView
  83. style={ui.flex1}>
  84. <TextView style={styles.textMessage}>{item.pinContent}</TextView>
  85. </ScrollView>
  86. </View>
  87. )
  88. }
  89. export default PinMessage;
  90. const styles = StyleSheet.create({
  91. pinMessageView: {
  92. top: 180,
  93. left: 16,
  94. right: 16,
  95. zIndex: 10,
  96. maxHeight: $vh(60),
  97. overflow: "hidden",
  98. position: 'absolute',
  99. },
  100. messageCard: {
  101. marginBottom: 16,
  102. maxHeight: $vh(50),
  103. overflow: "hidden",
  104. borderRadius: 6,
  105. backgroundColor: colorLight,
  106. ...ElevationObject(3)
  107. },
  108. marquee: {
  109. flex: 1,
  110. overflow: "hidden",
  111. ...$padding(12, 16)
  112. },
  113. textTitle: {
  114. color: textPrimary,
  115. fontSize: 16,
  116. fontWeight: "bold"
  117. },
  118. fixedTitle: {
  119. flex: 1,
  120. color: textPrimary,
  121. fontSize: 16,
  122. fontWeight: "bold",
  123. ...$padding(12, 16)
  124. },
  125. textMessage: {
  126. color: textSecondary,
  127. paddingLeft: 16,
  128. paddingRight: 16,
  129. paddingBottom: 16,
  130. fontSize: 14
  131. },
  132. noticeDialog: {
  133. width: Dialog.dialogWidth,
  134. height: $vw(100) + 48
  135. },
  136. closeIcon: {
  137. top: 8,
  138. right: 8,
  139. position: "absolute"
  140. },
  141. notiveView: {
  142. height: $vh(50) - 48,
  143. marginLeft: 4,
  144. marginRight: 4,
  145. borderRadius: 12,
  146. backgroundColor: colorLight
  147. },
  148. noticeTitle: {
  149. color: textPrimary,
  150. padding: 16,
  151. fontSize: 16,
  152. fontWeight: "bold",
  153. marginRight: 16
  154. }
  155. })