url.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. 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.buttonImport}
  52. onPress={this.onPressImport}
  53. >
  54. <Text style={styles.buttonImportText}>Import</Text>
  55. </TouchableOpacity>
  56. <TouchableOpacity
  57. style={styles.buttonCancel}
  58. onPress={ev => this.props.onDone()}
  59. >
  60. <Text style={styles.buttonCancelText}>Cancel</Text>
  61. </TouchableOpacity>
  62. </View>
  63. )
  64. }
  65. }
  66. const styles = StyleSheet.create({
  67. container: {
  68. flex: 1,
  69. alignItems: 'center',
  70. justifyContent: 'center',
  71. },
  72. input: {
  73. width: '90%',
  74. height: 40,
  75. borderColor: '#7f8a93',
  76. borderWidth: 1,
  77. padding: 5,
  78. borderRadius: 4,
  79. marginBottom: 15,
  80. },
  81. buttonImport: {
  82. alignItems: 'center',
  83. backgroundColor: '#2275d7',
  84. paddingHorizontal: 25,
  85. paddingVertical: 8,
  86. borderRadius: 5,
  87. marginBottom: 10,
  88. },
  89. buttonCancel: {
  90. alignItems: 'center',
  91. paddingHorizontal: 15,
  92. paddingVertical: 8,
  93. borderRadius: 5,
  94. },
  95. buttonImportText: {
  96. color: '#fff',
  97. },
  98. buttonCancelText: {
  99. color: '#0077cc',
  100. },
  101. })