url.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react'
  2. import {
  3. StyleSheet,
  4. TouchableOpacity,
  5. Text,
  6. TextInput,
  7. View } from 'react-native'
  8. import Url from '@uppy/url'
  9. export default class UppyRNUrl extends React.Component {
  10. constructor () {
  11. super()
  12. this.state = {
  13. url: null
  14. }
  15. this.onPressImport = this.onPressImport.bind(this)
  16. }
  17. componentDidMount () {
  18. const uppy = this.props.uppy
  19. const options = Object.assign(
  20. { id: 'uppyRN:Url' },
  21. this.props,
  22. { }
  23. )
  24. delete options.uppy
  25. uppy.use(Url, options)
  26. this.plugin = uppy.getPlugin(options.id)
  27. }
  28. componentWillUnmount () {
  29. const uppy = this.props.uppy
  30. uppy.removePlugin(this.plugin)
  31. }
  32. onPressImport () {
  33. this.plugin.addFile(this.state.url)
  34. .then(this.props.onSuccess)
  35. .catch((err) => {
  36. console.log(err)
  37. })
  38. }
  39. render () {
  40. return (
  41. <View style={styles.container}>
  42. <TextInput
  43. style={styles.input}
  44. autoFocus
  45. onChangeText={(text) => this.setState({
  46. url: text
  47. })}
  48. placeholder="Enter URL to import a file"
  49. />
  50. <TouchableOpacity
  51. style={styles.button}
  52. onPress={this.onPressImport}>
  53. <Text style={styles.buttonText}>Import</Text>
  54. </TouchableOpacity>
  55. <Text>{this.state.text}</Text>
  56. </View>
  57. )
  58. }
  59. }
  60. const styles = StyleSheet.create({
  61. container: {
  62. flex: 1,
  63. alignItems: 'center',
  64. justifyContent: 'center'
  65. },
  66. input: {
  67. width: '90%',
  68. height: 40,
  69. borderColor: '#7f8a93',
  70. borderWidth: 1,
  71. padding: 5,
  72. borderRadius: 4,
  73. marginBottom: 15
  74. },
  75. button: {
  76. alignItems: 'center',
  77. backgroundColor: '#2275d7',
  78. paddingHorizontal: 15,
  79. paddingVertical: 8
  80. },
  81. buttonText: {
  82. color: '#fff'
  83. }
  84. })