Skip to content

Instantly share code, notes, and snippets.

@watanabeyu
Last active October 5, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watanabeyu/0992cf7a6ea7ba5ee5afe714a5473fbc to your computer and use it in GitHub Desktop.
Save watanabeyu/0992cf7a6ea7ba5ee5afe714a5473fbc to your computer and use it in GitHub Desktop.
import * as React from 'react';
import { Text, View, StyleSheet,TouchableOpacity,CameraRoll,Linking } from 'react-native';
import { Constants,FileSystem,Permissions } from 'expo';
export default class App extends React.Component {
onPress = async () => {
const filePath = `${FileSystem.documentDirectory}share-movie.mp4`;
const res = await FileSystem.downloadAsync('http://techslides.com/demos/sample-videos/small.mp4', filePath);
// const i = await FileSystem.getInfoAsync(res.uri);
// console.log(i);
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
try{
const result = await CameraRoll.saveToCameraRoll(res.uri,"video");
Linking.openURL(`instagram://library?AssetPath=${encodeURIComponent(result)}`);
}
catch(e){
console.warn(JSON.stringify(e))
}
}
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this.onPress}>
<Text>download and getinfo</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
color: '#34495e',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment