react-native-fetch-blob
react-native-fetch-blob copied to clipboard
RNFetchBlob.ios.openDocument doesn't work when state change
Hi,
Thank you for RNFetchBlob. I am currently using the 0.10.8 version and I am able to open files both on iOS and Android.
I want now to display a Spinner so user can understand that something is happening after his tap. The problem is that if I set state "isLoading: true" and when RNFetchBlob.ios.openDocument is called I set state to "isLoading: false" the document doesn't open!
The promise of RNFetchBlob.ios.openDocument returns successfully.
This is my code for the iOS part: `
LOG.debug("Alert :: Downloading file, ios");
this.setState({isLoading:true});
RNFetchBlob
.config({
fileCache : true,
path: dirs.DocumentDir + "/" + attachmentName
})
.fetch('GET', attachmentUrl, {
//some headers ..
})
.then((res) => {
this.setState({isLoading:false});
return res;
})
.then((res) => {
// the temp file path
LOG.debug('The file saved to ', {res:res, resPath:res.path()});
try{
LOG.debug("Alert :: Open Document", dirs.DocumentDir + "/" + attachmentName);
RNFetchBlob.ios.openDocument(dirs.DocumentDir + "/" + attachmentName);
}catch(error){
LOG.error("Alert :: iOS Error opening file", {error:error, message:error.message});
this.setState({isLoading:false});
Toast.show({
text: "Errore durante il download del file. Verifica di essere connesso ad internet.",
position: 'bottom',
buttonText: 'OK',
duration:300000
});
}
}, (error) => {
LOG.error("Alert :: iOS errore durante il fetch del file", {error:error, message:error.message});
this.setState({isLoading:false});
Toast.show({
text: "Errore durante il download del file. Verifica di essere connesso ad internet.",
position: 'bottom',
buttonText: 'OK',
duration:300000
});
})`
I have tried multiple solutions like set isLoading in RNFetchBlob.ios.openDocument(..).then(fn(){set is loading to false}) or after "LOG.debug("Alert :: Open Document", dirs.DocumentDir + "/" + attachmentName);" but no solution works.
The spinner is "react-native-loading-spinner-overlay" and it's easy and fast. It seems to me that the openDocument function has problems with overlays/alert/modals because even in this StackOverflow question ([https://stackoverflow.com/questions/47511965/react-native-fetch-blob-ios-api-opendocument-not-working]) there is the same problem using Alerts.
Is there someone who solved this problem?
I can confirm that it's not the state change the problem. If I set change and I use an activity indicator on the right side of my attachment list all works perfectly.
The problem born with Alerts and Modals
Thanks for this - I was having problems with RNFetchBlob.ios.openDocument and had no clue it was because I had a modal open. This is a bug and there should be a warning in the docs!
Hi to all, the problem with Modal still exists! (I have not tried with Alerts) I open a new issue in the joltup repository making reference to this.