PinMessage.js 5.0 KB

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