-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
example: revive react native example #4164
Merged
Murderlon
merged 11 commits into
transloadit:main
from
giacomocerquone:react-native-fixes
Jan 5, 2023
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
53cbf76
examples: revive react native example
giacomocerquone 6ee8d08
fix: move peerdeps to direct deps
giacomocerquone 5cee3e3
fix: lint files, rollout useUppy react native hook
giacomocerquone 84a1e30
feat: migrate asyncstorage, linting files
giacomocerquone 2023175
fix: import StyleSheet
giacomocerquone 12a3fe1
fix: import useUppy from uppy/react
giacomocerquone bd52896
refactor: app example
giacomocerquone 7b38fa7
Merge branch 'main' of https://github.com/transloadit/uppy into react…
giacomocerquone 824d173
@uppy/react-native: upgrade document and image picker libraries
giacomocerquone 2fc4daa
@uppy-example/react-native-expo: fix package name
giacomocerquone 1243cd7
@uppy-example/react-native: change lockfile
giacomocerquone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"rules": { | ||
"react/react-in-jsx-scope": "off" | ||
"react/react-in-jsx-scope": "off", | ||
"no-use-before-define": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true, | ||
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
node_modules/**/* | ||
.expo/* | ||
node_modules/ | ||
.expo/ | ||
dist/ | ||
npm-debug.* | ||
*.jks | ||
*.p8 | ||
*.p12 | ||
*.key | ||
*.mobileprovision | ||
*.orig.* | ||
web-build/ | ||
|
||
# macOS | ||
.DS_Store |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,175 +1,172 @@ | ||
// import * as Expo from 'expo' | ||
import React from 'react' | ||
import { | ||
Text, | ||
View, | ||
AsyncStorage, | ||
Image, | ||
} from 'react-native' | ||
import React, { useEffect, useState, useCallback } from 'react' | ||
import { Text, View, Image, StyleSheet } from 'react-native' | ||
import AsyncStorage from '@react-native-async-storage/async-storage' | ||
import Uppy from '@uppy/core' | ||
import Tus from '@uppy/tus' | ||
import UppyFilePicker from '@uppy/react-native' | ||
import FilePicker from '@uppy/react-native' | ||
import useUppy from '@uppy/react/lib/useUppy' | ||
import FileList from './FileList' | ||
import PauseResumeButton from './PauseResumeButton' | ||
import ProgressBar from './ProgressBar' | ||
import SelectFiles from './SelectFilesButton' | ||
import getTusFileReader from './tusFileReader' | ||
|
||
export default class App extends React.Component { | ||
constructor () { | ||
super() | ||
|
||
this.state = { | ||
progress: 0, | ||
total: 0, | ||
file: null, | ||
uploadURL: null, | ||
isFilePickerVisible: false, | ||
isPaused: false, | ||
uploadStarted: false, | ||
uploadComplete: false, | ||
info: null, | ||
totalProgress: 0, | ||
} | ||
|
||
this.isReactNative = (typeof navigator !== 'undefined' | ||
&& typeof navigator.product === 'string' | ||
&& navigator.product.toLowerCase() === 'reactnative') | ||
|
||
this.showFilePicker = this.showFilePicker.bind(this) | ||
this.hideFilePicker = this.hideFilePicker.bind(this) | ||
this.togglePauseResume = this.togglePauseResume.bind(this) | ||
export default function App () { | ||
const [state, _setState] = useState({ | ||
progress: 0, | ||
total: 0, | ||
file: null, | ||
uploadURL: null, | ||
isFilePickerVisible: false, | ||
isPaused: false, | ||
uploadStarted: false, | ||
uploadComplete: false, | ||
info: null, | ||
totalProgress: 0, | ||
}) | ||
|
||
const setState = useCallback((newState) => _setState((oldState) => ({ ...oldState, ...newState })), []) | ||
|
||
const uppy = useUppy(() => { | ||
return new Uppy({ autoProceed: true, debug: true }) | ||
.use(Tus, { | ||
endpoint: 'https://tusd.tusdemo.net/files/', | ||
urlStorage: AsyncStorage, | ||
fileReader: getTusFileReader, | ||
chunkSize: 10 * 1024 * 1024, // keep the chunk size small to avoid memory exhaustion | ||
}) | ||
}) | ||
|
||
console.log('Is this React Native?', this.isReactNative) | ||
this.uppy = new Uppy({ autoProceed: true, debug: true }) | ||
this.uppy.use(Tus, { | ||
endpoint: 'https://tusd.tusdemo.net/files/', | ||
urlStorage: AsyncStorage, | ||
fileReader: getTusFileReader, | ||
chunkSize: 10 * 1024 * 1024, // keep the chunk size small to avoid memory exhaustion | ||
}) | ||
this.uppy.on('upload-progress', (file, progress) => { | ||
this.setState({ | ||
useEffect(() => { | ||
uppy.on('upload-progress', (file, progress) => { | ||
setState({ | ||
progress: progress.bytesUploaded, | ||
total: progress.bytesTotal, | ||
totalProgress: this.uppy.state.totalProgress, | ||
totalProgress: uppy.state.totalProgress, | ||
uploadStarted: true, | ||
}) | ||
}) | ||
this.uppy.on('upload-success', () => { | ||
uppy.on('upload-success', () => { | ||
// console.log(file.name, response) | ||
}) | ||
this.uppy.on('complete', (result) => { | ||
this.setState({ | ||
status: 'Upload complete ✅', | ||
uppy.on('complete', (result) => { | ||
setState({ | ||
status: result.successful[0] ? 'Upload complete ✅' : 'Upload errored ❌', | ||
uploadURL: result.successful[0] ? result.successful[0].uploadURL : null, | ||
uploadComplete: true, | ||
uploadStarted: false, | ||
}) | ||
console.log('Upload complete:', result) | ||
}) | ||
|
||
this.uppy.on('info-visible', () => { | ||
const { info } = this.uppy.getState() | ||
this.setState({ | ||
uppy.on('info-visible', () => { | ||
const { info } = uppy.getState() | ||
setState({ | ||
info, | ||
}) | ||
console.log('uppy-info:', info) | ||
}) | ||
|
||
this.uppy.on('info-hidden', () => { | ||
this.setState({ | ||
uppy.on('info-hidden', () => { | ||
setState({ | ||
info: null, | ||
}) | ||
}) | ||
} | ||
}, [setState, uppy]) | ||
|
||
showFilePicker () { | ||
this.setState({ | ||
const showFilePicker = () => { | ||
setState({ | ||
isFilePickerVisible: true, | ||
uploadStarted: false, | ||
uploadComplete: false, | ||
}) | ||
} | ||
|
||
hideFilePicker () { | ||
this.setState({ | ||
const hideFilePicker = () => { | ||
setState({ | ||
isFilePickerVisible: false, | ||
}) | ||
} | ||
|
||
togglePauseResume () { | ||
if (this.state.isPaused) { | ||
this.uppy.resumeAll() | ||
this.setState({ | ||
const togglePauseResume = () => { | ||
if (state.isPaused) { | ||
uppy.resumeAll() | ||
setState({ | ||
isPaused: false, | ||
}) | ||
} else { | ||
this.uppy.pauseAll() | ||
this.setState({ | ||
uppy.pauseAll() | ||
setState({ | ||
isPaused: true, | ||
}) | ||
} | ||
} | ||
|
||
render () { | ||
return ( | ||
<View style={{ | ||
paddingTop: 100, | ||
paddingLeft: 50, | ||
paddingRight: 50, | ||
flex: 1, | ||
}} | ||
return ( | ||
<View | ||
style={styles.root} | ||
> | ||
<Text | ||
style={styles.title} | ||
> | ||
<Text style={{ | ||
fontSize: 25, | ||
marginBottom: 20, | ||
textAlign: 'center', | ||
}} | ||
Uppy in React Native | ||
</Text> | ||
<View style={{ alignItems: 'center' }}> | ||
<Image | ||
style={styles.logo} | ||
source={require('./assets/uppy-logo.png')} | ||
/> | ||
</View> | ||
<SelectFiles showFilePicker={showFilePicker} /> | ||
|
||
{state.info ? ( | ||
<Text | ||
style={{ | ||
marginBottom: 10, | ||
marginTop: 10, | ||
color: '#b8006b', | ||
}} | ||
> | ||
Uppy in React Native | ||
{state.info.message} | ||
</Text> | ||
<View style={{ alignItems: 'center' }}> | ||
<Image | ||
style={{ width: 80, height: 78, marginBottom: 50 }} | ||
source={require('./assets/uppy-logo.png')} | ||
/> | ||
</View> | ||
<SelectFiles showFilePicker={this.showFilePicker} /> | ||
|
||
{this.state.info ? ( | ||
<Text | ||
style={{ | ||
marginBottom: 10, | ||
marginTop: 10, | ||
color: '#b8006b', | ||
}} | ||
> | ||
{this.state.info.message} | ||
</Text> | ||
) : null} | ||
|
||
<ProgressBar progress={this.state.totalProgress} /> | ||
|
||
<PauseResumeButton | ||
isPaused={this.state.isPaused} | ||
onPress={this.togglePauseResume} | ||
uploadStarted={this.state.uploadStarted} | ||
uploadComplete={this.state.uploadComplete} | ||
/> | ||
|
||
<UppyFilePicker | ||
uppy={this.uppy} | ||
show={this.state.isFilePickerVisible} | ||
onRequestClose={this.hideFilePicker} | ||
) : null} | ||
|
||
<ProgressBar progress={state.totalProgress} /> | ||
|
||
<PauseResumeButton | ||
isPaused={state.isPaused} | ||
onPress={togglePauseResume} | ||
uploadStarted={state.uploadStarted} | ||
uploadComplete={state.uploadComplete} | ||
/> | ||
|
||
{uppy && ( | ||
<FilePicker | ||
uppy={uppy} | ||
show={state.isFilePickerVisible} | ||
onRequestClose={hideFilePicker} | ||
companionUrl="http://localhost:3020" | ||
/> | ||
)} | ||
|
||
<FileList uppy={this.uppy} /> | ||
{uppy && <FileList uppy={uppy} />} | ||
|
||
{/* <Text>{this.state.status ? 'Status: ' + this.state.status : null}</Text> | ||
<Text>{this.state.progress} of {this.state.total}</Text> */} | ||
</View> | ||
) | ||
} | ||
{state.status && <Text>Status: {state.status}</Text>} | ||
<Text>{state.progress} of {state.total}</Text> | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
paddingTop: 100, | ||
paddingBottom: 20, | ||
paddingLeft: 50, | ||
paddingRight: 50, | ||
flex: 1, | ||
}, | ||
title: { | ||
fontSize: 25, | ||
marginBottom: 20, | ||
textAlign: 'center', | ||
}, | ||
logo: { width: 80, height: 78, marginBottom: 50 }, | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
within the react-native-expo example "React" is considered an unused var, but if it's removed I get the following error.
The fix should actually be smarter and not just a rule exclusion