ItemAlert.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * 通知消息渲染项目组件
  3. * @邠心vbe on 2023/08/17
  4. */
  5. import React from 'react';
  6. import { Pressable, StyleSheet, View } from 'react-native';
  7. import TextView from '../../components/TextView';
  8. const IconType = ({type, style, size=32, color=colorAccent}) => {
  9. switch (type) {
  10. case "Applications":
  11. return (
  12. <MaterialIcons
  13. name="admin-panel-settings"
  14. size={size}
  15. style={style}
  16. color={color}
  17. />
  18. )
  19. case "Admin":
  20. return (
  21. <MaterialCommunityIcons
  22. name="message-draw"
  23. size={size}
  24. style={style}
  25. color={color}
  26. />
  27. )
  28. case "Charging":
  29. return (
  30. <MaterialIcons
  31. name="offline-bolt"
  32. size={size}
  33. style={style}
  34. color={color}
  35. />
  36. )
  37. case "Wallet":
  38. return (
  39. <MaterialCommunityIcons
  40. name="cash-multiple"
  41. size={size}
  42. style={style}
  43. color={color}
  44. />
  45. )
  46. case "Announcement":
  47. return (
  48. <MaterialCommunityIcons
  49. name="message-alert"
  50. size={size}
  51. style={style}
  52. color={color}
  53. />
  54. )
  55. case "Review":
  56. return (
  57. <MaterialCommunityIcons
  58. name="message-draw"
  59. size={size}
  60. style={style}
  61. color={color}
  62. />
  63. )
  64. case "Promotion":
  65. return (
  66. <MaterialCommunityIcons
  67. name="bullhorn-variant"
  68. size={size}
  69. style={style}
  70. color={color}
  71. />
  72. )
  73. default:
  74. return (
  75. <MaterialCommunityIcons
  76. name="message-alert"
  77. size={size}
  78. style={style}
  79. color={color}
  80. />
  81. )
  82. }
  83. }
  84. export default ItemAlert = ({item, index, separators, onPress, onLongPress}) => {
  85. const getDotColor = () => {
  86. if (item.readStatus) {
  87. if (item?.notificationTitle.indexOf("Low") >= 0/* || item.notificationType == "Announcement"*/) {
  88. return "#F09327";
  89. } else {
  90. return colorAccent;
  91. }
  92. } else {
  93. return "#FF3B30";
  94. }
  95. }
  96. return (
  97. <Pressable
  98. style={item.readStatus ? styles.notyItemView : styles.unotyItemView}
  99. onPress={onPress}
  100. android_ripple={ripple}
  101. onLongPress={onLongPress}>
  102. <IconType
  103. style={styles.iconType}
  104. type={item.notificationType}
  105. color={getDotColor()}
  106. />
  107. <View style={styles.itemContent}>
  108. <TextView
  109. style={styles.textTitle}
  110. numberOfLines={1}
  111. ellipsizeMode="tail">
  112. {item.notificationTitle}
  113. </TextView>
  114. <TextView
  115. style={styles.textDate}
  116. numberOfLines={1}>
  117. <MaterialCommunityIcons
  118. name="clock-time-four-outline"
  119. size={10}
  120. style={styles.textDate}/>
  121. {" " + item.createTime}
  122. </TextView>
  123. <TextView
  124. style={styles.textMessage}
  125. numberOfLines={2}>
  126. {item.notificationText}
  127. </TextView>
  128. </View>
  129. </Pressable>
  130. )
  131. }
  132. const styles = StyleSheet.create({
  133. notyItemView: {
  134. padding: 16,
  135. flexDirection: 'row'
  136. },
  137. unotyItemView: {
  138. padding: 16,
  139. flexDirection: 'row',
  140. backgroundColor: "#F0F0F0"
  141. },
  142. iconType: {
  143. marginRight: 12
  144. },
  145. readIcon: {
  146. top: 2,
  147. left: -5,
  148. width: 7,
  149. height: 6,
  150. position: 'absolute'
  151. },
  152. itemContent: {
  153. flex: 1
  154. },
  155. textTitle: {
  156. flex: 1,
  157. color: textPrimary,
  158. fontSize: 15,
  159. fontWeight: 'bold',
  160. paddingBottom: 4
  161. },
  162. textDate: {
  163. color: textSecondary,
  164. fontSize: 10,
  165. lineHeight: 10,
  166. paddingBottom: 4
  167. },
  168. unread: {
  169. fontWeight: 'bold'
  170. },
  171. textMessage: {
  172. color: textPrimary,
  173. fontSize: 12
  174. }
  175. })