Created
November 2, 2016 19:53
-
-
Save raminious/60f9183f1875023ec7c819203681e89c to your computer and use it in GitHub Desktop.
this snippet code should throw an error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* @flow | |
*/ | |
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View, | |
TextInput, | |
TouchableOpacity | |
} from 'react-native' | |
import RNFetchBlob from 'react-native-fetch-blob' | |
export default class blob extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
url: '', | |
received: 0, | |
total: 0, | |
path: null | |
} | |
} | |
download = () => { | |
const {url} = this.state | |
const filename = 'small.mp4' | |
const path = RNFetchBlob.fs.dirs.DocumentDir + '/' + filename | |
console.log(url, path) | |
RNFetchBlob | |
.config({ | |
addAdnroidDownloads: { | |
useDownloadManager: true, | |
notification: true, | |
description: filename, | |
meidaScannable: true | |
}, | |
fileCache : true, | |
path | |
}) | |
.fetch('GET', url) | |
.progress({ interval: 1000 }, (received, total) => { | |
this.setState({received, total}) | |
}) | |
.then((res) => { | |
this.setState({ | |
path: res.path() | |
}) | |
}, e => { | |
console.log(e) | |
}) | |
} | |
openfile = () => { | |
RNFetchBlob.ios.openDocument(this.state.path).then(r => r, e => e) | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<TextInput | |
value={this.state.url} | |
onChangeText={(url) => this.setState({url})} | |
placeholder='enter url' | |
style={{ width: 300, height: 30 }} /> | |
<TouchableOpacity onPress={this.download}> | |
<Text>Download</Text> | |
</TouchableOpacity> | |
<Text style={{ marginTop: 40 }}>{ this.state.received } / { this.state.total} </Text> | |
{ | |
this.state.path != null && | |
<View style={{ marginTop: 40 }}> | |
<TouchableOpacity onPress={this.openfile}> | |
<Text>Open { this.state.path }</Text> | |
</TouchableOpacity> | |
</View> | |
} | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
marginTop: 100, | |
} | |
}); | |
AppRegistry.registerComponent('blob', () => blob); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment