url.js 2.2 KB

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