ItemView.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * 通知消息渲染项目组件
  3. * @邠心vbe on 2023/08/17
  4. */
  5. import React from 'react';
  6. import { Pressable, StyleSheet, Text, 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 ItemView = ({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={styles.notyItemView}
  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. <View style={ui.flexc}>
  109. <TextView
  110. style={[styles.textTitle, (!item.readStatus && styles.unread)]}
  111. numberOfLines={1}
  112. ellipsizeMode="tail">
  113. {item.notificationTitle}
  114. </TextView>
  115. <TextView
  116. style={[styles.textDate, (!item.readStatus && styles.unread)]}
  117. numberOfLines={1}>
  118. {item.createTime}
  119. </TextView>
  120. </View>
  121. <TextView
  122. style={styles.textMessage}
  123. numberOfLines={2}>
  124. {item.notificationText}
  125. </TextView>
  126. </View>
  127. </Pressable>
  128. )
  129. }
  130. const styles = StyleSheet.create({
  131. notyItemView: {
  132. padding: 16,
  133. alignItems: 'center',
  134. flexDirection: 'row'
  135. },
  136. iconType: {
  137. marginRight: 12
  138. },
  139. readIcon: {
  140. top: 2,
  141. left: -5,
  142. width: 7,
  143. height: 6,
  144. position: 'absolute'
  145. },
  146. itemContent: {
  147. flex: 1
  148. },
  149. textTitle: {
  150. flex: 1,
  151. color: textPrimary,
  152. fontSize: 15
  153. },
  154. textDate: {
  155. color: textPrimary,
  156. fontSize: 12
  157. },
  158. unread: {
  159. fontWeight: 'bold'
  160. },
  161. textMessage: {
  162. color: textPrimary,
  163. fontSize: 12
  164. }
  165. })