url.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. this.uppy = this.props.uppy
  19. this.uppy.use(Url, {
  20. id: 'uppyRN:Url',
  21. serverUrl: 'http://localhost:3020'
  22. })
  23. this.plugin = this.uppy.getPlugin('uppyRN:Url')
  24. }
  25. componentWillUnmount () {
  26. this.uppy.removePlugin(this.plugin)
  27. }
  28. onPressImport () {
  29. this.plugin.addFile(this.state.url)
  30. .then(() => {
  31. console.log('success')
  32. })
  33. .catch((err) => {
  34. console.log(err)
  35. })
  36. }
  37. render () {
  38. return (
  39. <View style={{
  40. flex: '1',
  41. alignItems: 'center',
  42. justifyContent: 'center'
  43. }}>
  44. <TextInput
  45. style={{
  46. width: '90%',
  47. height: 40,
  48. borderColor: '#7f8a93',
  49. borderWidth: 1,
  50. padding: 5,
  51. marginBottom: 15
  52. }}
  53. onChangeText={(text) => this.setState({
  54. url: text
  55. })}
  56. placeholder="Enter URL to import a file"
  57. />
  58. <TouchableOpacity
  59. style={{
  60. alignItems: 'center',
  61. backgroundColor: '#2275d7',
  62. paddingHorizontal: 15,
  63. paddingVertical: 8
  64. }}
  65. onPress={this.onPressImport}>
  66. <Text style={{ color: '#fff' }}>Import</Text>
  67. </TouchableOpacity>
  68. <Text>{this.state.text}</Text>
  69. </View>
  70. )
  71. }
  72. }
  73. // const styles = StyleSheet.create({
  74. // container: {
  75. // justifyContent: 'center',
  76. // flex: 1,
  77. // paddingTop: 30
  78. // },
  79. // item: {
  80. // justifyContent: 'center',
  81. // alignItems: 'center',
  82. // height: 100
  83. // }
  84. // })