ItemView.js 3.5 KB

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