wkh237 / react-native-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.61k stars 1.59k forks source link

Feature: ios.previewDocument/openDocument custom action button #198

Closed blackburnian closed 7 years ago

blackburnian commented 7 years ago

We are downloading an opening a PDF via this code in our RN application:

RNFetchBlob.config({
    path: dirs.DocumentDir + '/test.pdf'
})
    .fetch('GET', `https://www.ets.org/Media/Tests/TOEFL/pdf/SampleQuestions.pdf`)
    .then((res) => {
                RNFetchBlob.ios.openDocument(res.path());
    })

This works beautifully: img_0671

However, in our scenario, we need to prevent the user from sharing the PDF or doing anything else with it besides viewing it. We do however want to offer them the option to save it locally to their phone which we can also use your plugin for. Is there a way to pass some options to the openDocument method which would allow us to put a 'Save' button (instead of that action icon image) and give us a callback that we can fire when they click on it? Something like:

RNFetchBlob.config({
    path: dirs.DocumentDir + '/test.pdf'
})
    .fetch('GET', `https://www.ets.org/Media/Tests/TOEFL/pdf/SampleQuestions.pdf`)
    .then((res) => {
                RNFetchBlob.ios.openDocument(res.path(), {
                    actionButtonText: 'Save',
                    actionButtonCallback: () => {

                    }                
                });
    })
blackburnian commented 7 years ago

Oh, by the way, on your documentation, I think you need to switch the openDocument and previewDocument methods. It shows the openDocument method as the method that brings up the options menu: image when in fact it's the previewDocument method that does that.

wkh237 commented 7 years ago

@blackburnian , thanks for the advice, but I'm not sure if this is possible because looks like a platform limitation, it there's any information we can try to do this 😄

dwilt commented 7 years ago

@wkh237 I noticed in your documentation, that the UIDocumentInteractionController is used. I did some quick googling about that and found this. If we can set the button to nil, could we also have it provide a value?

wkh237 commented 7 years ago

@dwilt , I've tried the approach mentioned in the SO thread but it does not work for me, on the other hand, it needs to change AppDelegate.m so I think we are not be able to add this feature to this package.