import * as Expo from 'expo' import React from 'react' import { Text, View, Button, TouchableOpacity, TouchableHighlight, Image, Linking } from 'react-native' import Uppy from '@uppy/core' import Tus from '@uppy/tus' import UppyFilePicker from './react-native/file-picker' export default class App extends React.Component { constructor () { super() this.state = { progress: 0, total: 0, file: null, uploadURL: null, isFilePickerVisible: false } this.isReactNative = (typeof navigator !== 'undefined' && 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) console.log('Is this React Native?', this.isReactNative) this.uppy = Uppy({ autoProceed: true, debug: true }) this.uppy.use(Tus, { endpoint: 'https://master.tus.io/files/' }) this.uppy.on('upload-progress', (file, progress) => { this.setState({ progress: progress.bytesUploaded, total: progress.bytesTotal }) }) this.uppy.on('complete', (result) => { this.setState({ status: 'Upload complete ✅', uploadURL: result.successful[0].uploadURL }) console.log('Upload complete:') console.log(this.uppy.state.files) }) } 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.addFile(result) } }) }) } startUpload () { this.setState({ status: 'Uploading...' }) } showFilePicker () { this.setState({ isFilePickerVisible: true }) } hideFilePicker () { this.setState({ isFilePickerVisible: false }) } render () { return ( ) } } function SelectAndUploadFileWithUppy (props) { return ( Uppy running in React Native { props.state.file === null ? Select a Photo : } { props.state.uploadURL !== null &&