PinMessage.js 4.2 KB

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