FileList.js 2.8 KB

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