From 0cdcd4a74e564e758f2ba68ef6bf527c2cf5d154 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Wed, 3 Apr 2019 15:28:14 +0300 Subject: [PATCH] Refactor and add file previews --- examples/react-native-expo/App.js | 209 +++--------------- examples/react-native-expo/FileList.js | 43 ++++ .../react-native-expo/PauseResumeButton.js | 29 +++ examples/react-native-expo/ProgressBar.js | 32 +++ .../react-native-expo/SelectFilesButton.js | 20 ++ .../react-native/file-picker/index.js | 6 +- 6 files changed, 158 insertions(+), 181 deletions(-) create mode 100644 examples/react-native-expo/FileList.js create mode 100644 examples/react-native-expo/PauseResumeButton.js create mode 100644 examples/react-native-expo/ProgressBar.js create mode 100644 examples/react-native-expo/SelectFilesButton.js diff --git a/examples/react-native-expo/App.js b/examples/react-native-expo/App.js index ea62191c7..f8c9875a4 100644 --- a/examples/react-native-expo/App.js +++ b/examples/react-native-expo/App.js @@ -2,16 +2,17 @@ import React from 'react' import { Text, - View, - AsyncStorage, - // TouchableOpacity, - TouchableHighlight - // Image, + View + // AsyncStorage // Linking } from 'react-native' import Uppy from '@uppy/core' import Tus from '@uppy/tus' import UppyFilePicker from './react-native/file-picker' +import FileList from './FileList' +import PauseResumeButton from './PauseResumeButton' +import ProgressBar from './ProgressBar' +import SelectFiles from './SelectFilesButton' function hashCode (str) { // from https://stackoverflow.com/a/8831937/151666 @@ -28,15 +29,11 @@ function hashCode (str) { } function customFingerprint (file, options) { - console.log('_____________________') - console.log('FILE:') - console.log(file) - console.log('_____________________') let exifHash = 'noexif' if (file.exif) { exifHash = hashCode(JSON.stringify(file.exif)) } - console.log(exifHash) + // console.log(exifHash) const fingerprint = ['tus', file.name || 'noname', file.size || 'nosize', exifHash].join('/') console.log(fingerprint) return fingerprint @@ -61,8 +58,6 @@ export default class App extends React.Component { typeof navigator.product === 'string' && navigator.product.toLowerCase() === 'reactnative') - this.startUpload = this.startUpload.bind(this) - // this.selectPhotoTapped = this.selectPhotoTapped.bind(this) this.showFilePicker = this.showFilePicker.bind(this) this.hideFilePicker = this.hideFilePicker.bind(this) this.togglePauseResume = this.togglePauseResume.bind(this) @@ -71,7 +66,7 @@ export default class App extends React.Component { this.uppy = Uppy({ autoProceed: true, debug: true }) this.uppy.use(Tus, { endpoint: 'https://master.tus.io/files/', - urlStorage: AsyncStorage, + // urlStorage: AsyncStorage, fingerprint: customFingerprint }) this.uppy.on('upload-progress', (file, progress) => { @@ -96,36 +91,6 @@ export default class App extends React.Component { }) } - // selectPhotoTapped () { - // console.log('Selecting photo...') - - // Expo.Permissions.askAsync(Expo.Permissions.CAMERA_ROLL).then((isAllowed) => { - // if (!isAllowed) return - - // Expo.ImagePicker.launchImageLibraryAsync({ - // mediaTypes: 'All' - // }) - // .then((result) => { - // console.log(result) - // if (!result.cancelled) { - // this.setState({ file: result }) - // this.uppy.addFile({ - // source: 'React Native', - // name: 'photo.jpg', - // type: result.type, - // data: result - // }) - // } - // }) - // }) - // } - - startUpload () { - this.setState({ - status: 'Uploading...' - }) - } - showFilePicker () { this.setState({ isFilePickerVisible: true, @@ -154,151 +119,39 @@ export default class App extends React.Component { } } - resumeAll () { - this.uppy.resumeAll() - this.setState({ - isPaused: false - }) - } - render () { return ( - + Uppy in React Native + + + + + + + + {this.state.status ? 'Status: ' + this.state.status : null} + {this.state.progress} of {this.state.total} ) } } - -function ProgressBar (props) { - const progress = props.progress || 0 - const total = props.total || 0 - const percentage = Math.round(progress / total * 100) - - const colorGreen = '#0b8600' - const colorBlue = '#006bb7' - - return ( - - - - - {percentage ? percentage + '%' : null} - - ) -} - -function PauseResumeButton (props) { - if (!props.uploadStarted || props.uploadComplete) { - return null - } - - // return ( - //