I can't seem to get this to work i know. the "onFileDownload={ ( { nativeEvent: { downloadUrl } } ) => {" has been added and i need my own code to make this work. I tried to use expo file system and expo sharing to get this to download but it's not working. all i want is that when they download a pdf instead of a preview they can share the document or save it. Any help would be greatly appreciated.
Below is the code i tried to make it work but failed (the alert function works but then nothing happens):
import React, { Component } from 'react';
import { StyleSheet, ActivityIndicator, View, Platform, PermissionsAndroid, Alert } from 'react-native';
import * as Permissions from 'expo-permissions';
import { WebView } from 'react-native-webview';
//sharing and download
import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';
import { Image, Text, TouchableOpacity, } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
export default function App() {
let [selectedImage, setSelectedImage] = React.useState(null);
let openImagePickerAsync = async () => {
const downloadResumable = FileSystem.createDownloadResumable(
{downloadUrl},
${FileSystem.documentDirectory}/pdf.pdf,
{},
);
const { uri, status } = await downloadResumable.downloadAsync();
// setSelectedImage({ localUri: uri });
Sharing.shareAsync(uri);
};
let openShareDialogAsync = async () => {
if (!(await Sharing.isAvailableAsync())) {
alert(Uh oh, sharing isn't available on your platform);
return;
}
Sharing.shareAsync(selectedImage.localUri);
};
// if (selectedImage !== null) {
// return (
//
//
// Share this
//
//
// );
// }
return (
<View style={{ flex: 1 }}>
<WebView
style={{ flex: 1 }}
source={{ uri: 'http://www.pdf995.com/' }}
onFileDownload={ ( { nativeEvent: { downloadUrl } } ) => {
Alert.alert(
"Documents",
"Do you wish to download and share this document",
[
{
text: "Download",
onPress: () => {openImagePickerAsync}
},
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
],
{ cancelable: false }
);}
} />
</View>
);
}
I took the code from expo snack: https://snack.expo.io/@trinet/sharing Any help would be greatly appreciated. I'm really stuck