react-native-doc-viewer icon indicating copy to clipboard operation
react-native-doc-viewer copied to clipboard

Android: fileName has no effect

Open BigPun86 opened this issue 6 years ago • 0 comments

Env: "react": "16.4.0", "react-native": "0.53.3", "react-native-doc-viewer": "2.7.8"

The iOS part with file fileNameOptional works, but not the Android part on my Nexus 5X.

import RNFetchBlob from "react-native-fetch-blob";
import { Platform } from "react-native";
import OpenFile from "react-native-doc-viewer";

const OpenFileManager = OpenFile.openDoc;
const isIOS = Platform.OS === 'ios';
const fetchBlobOptions = { fileCache: true, appendExt: "pdf" };

export function PdfView(link: string, fileName: string) {
    return new Promise((resolve, reject) => {
        RNFetchBlob.config(fetchBlobOptions)
            .fetch("GET", link, {})
            .then(data => {
                const options = createFileManagerOptions(data, fileName);
                OpenFileManager(options,
                    (error, url) => {
                        if (error) {
                            reject(false);
                        } else {
                            resolve(true);
                        }
                    }
                );
            });
    });
}

function createFileManagerOptions(data: Object, fileName: string) {
    const options = [];
    if (isIOS) {
        options.push({
            fileNameOptional: fileName,
            url: data.path(),
        });
    } else {
        options.push({
            cache: false /*Use Cache Folder Android*/,
            fileName: fileName,
            fileType: "",
            url: "file:/" + data.path(),
        });
    }
    return options;
}

The name is always "RNFetchBlobTmp_q.........pdf"

Any ideas how to solve this? I checked the native part and in my eyes it looks good.

BigPun86 avatar Jul 19 '18 11:07 BigPun86