FileList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React from 'react' // eslint-disable-line no-unused-vars
  2. import { StyleSheet, View, FlatList, Text, Image } from 'react-native'
  3. import getFileTypeIcon from '@uppy/dashboard/lib/utils/getFileTypeIcon.js'
  4. import truncateString from '@uppy/dashboard/lib/utils/truncateString.js'
  5. import renderStringFromJSX from 'preact-render-to-string'
  6. // function truncateString (str) {
  7. // const maxChars = 20
  8. // if (str.length > maxChars) {
  9. // return str.substring(0, 25) + '...'
  10. // }
  11. // return str
  12. // }
  13. function FileIcon () {
  14. return (
  15. <View style={styles.itemIconContainer}>
  16. <Image
  17. style={styles.itemIcon}
  18. source={require('./assets/file-icon.png')}
  19. />
  20. </View>
  21. )
  22. }
  23. function UppyDashboardFileIcon (props) {
  24. const icon = renderStringFromJSX(getFileTypeIcon(props.type).icon)
  25. if (!icon) {
  26. return <FileIcon />
  27. }
  28. const { color } = getFileTypeIcon(props.type)
  29. return (
  30. <View
  31. style={{
  32. ...styles.itemIconContainer,
  33. backgroundColor: color,
  34. }}
  35. >
  36. <Text style={styles.itemType}>logo</Text>
  37. </View>
  38. )
  39. }
  40. export default function FileList (props) {
  41. const uppyFiles = props.uppy.state.files
  42. const uppyFilesArray = Object.keys(uppyFiles).map((id) => uppyFiles[id])
  43. return (
  44. <View style={styles.container}>
  45. <FlatList
  46. data={uppyFilesArray}
  47. keyExtractor={(item) => item.id}
  48. numColumns={2}
  49. renderItem={({ item }) => {
  50. return (
  51. <View style={styles.item}>
  52. {item.type === 'image' ? (
  53. <Image
  54. style={styles.itemImage}
  55. source={{ uri: item.data.uri }}
  56. />
  57. ) : (
  58. <UppyDashboardFileIcon type={item.type} />
  59. )}
  60. <Text style={styles.itemName}>{truncateString(item.name, 20)}</Text>
  61. <Text style={styles.itemType}>{item.type}</Text>
  62. </View>
  63. )
  64. }}
  65. />
  66. </View>
  67. )
  68. }
  69. const styles = StyleSheet.create({
  70. container: {
  71. marginTop: 20,
  72. marginBottom: 20,
  73. flex: 1,
  74. justifyContent: 'center',
  75. },
  76. item: {
  77. width: 100,
  78. marginTop: 5,
  79. marginBottom: 15,
  80. marginRight: 25,
  81. },
  82. itemImage: {
  83. width: 100,
  84. height: 100,
  85. borderRadius: 5,
  86. marginBottom: 5,
  87. },
  88. itemIconContainer: {
  89. width: 100,
  90. height: 100,
  91. borderRadius: 5,
  92. marginBottom: 5,
  93. backgroundColor: '#cfd3d6',
  94. alignItems: 'center',
  95. justifyContent: 'center',
  96. },
  97. itemIcon: {
  98. width: 42,
  99. height: 56,
  100. },
  101. itemIconSVG: {
  102. width: 50,
  103. height: 50,
  104. },
  105. itemName: {
  106. fontSize: 13,
  107. color: '#2c3e50',
  108. fontWeight: '600',
  109. },
  110. itemType: {
  111. fontWeight: '600',
  112. fontSize: 12,
  113. color: '#95a5a6',
  114. },
  115. })