FileList.js 2.0 KB

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