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