url.js 2.2 KB

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