on ios files are opened, but immediately closed themselves
tosh17 opened this issue · 6 comments
On Android all work fine.
But when i open file on ios - it opens for a split second and then closes itself. There are no errors in the logs
Same here. RN 0.61.1
Can you send a snippet of your code?
I solved the problem. As far as I understand under ios, you are calling a modal window, which conflicts with my code. I made a delay(300ms) to start the opening of the file so that my modal windows managed to close correctly
it's not a good idea, adding delay before opening file, do you have better solution?
I can reproduce this issue and use onDismiss method can avoid the file-viewer window automatically close immediately
import React, {PureComponent, Component} from 'react';
import {Platform, Image, Text, View, TouchableWithoutFeedback, Dimensions, StyleSheet} from 'react-native';
import Modal from 'react-native-modal';
import FileViewer from 'react-native-file-viewer';
import RNFetchBlob from 'rn-fetch-blob';
export default class TestScreen extends PureComponent {
constructor(props) {
super(props);
this.tabIndex = [];
this.state = {
isFileFetching: false,
};
}
downloadAndOpen() {
this.setState({isFileFetching: true});
const filePath = downloadsPath.concat('/', fileName);
RNFetchBlob.config({path: filePath})
.fetch('GET', 'https://xxxx.com/yyy.pdf')
.then(() => {
FileViewer.open(filePath, {
showOpenWithDialog: true,
onDismiss: () => this.setState({isFileFetching: false}),
}).catch((error) => {
this.setState({isFileFetching: false});
});
});
}
render() {
return (
<View>
<Modal isVisible={this.state.isFileFetching}>
<View>
<ActivityIndicator color={spinnerColor} size={size} />
</View>
</Modal>
<TouchableWithoutFeedback onPress={this.downloadAndOpen}>
<Text>download and open </Text>
</TouchableWithoutFeedback>
</View>
);
}
}
I assume you also use the react-native-modal for the downloading spinner, I don't know if there is some conflicts between react-native-modal and react-native-file-viewer, if you FileViewer.open() right after setting isVisible=false, the FileViewer window will be close automatically.
you can use the delay(300ms) between modal close and fileViewer open. but I think use onDismiss is a better solution
I have the same issue. I am using react-native-modal
and using the onModalHide
handler to call FileViewer.open
and yet it still occurs...I am somewhat reluctant to use setTimout as the timeout might not be enough if the user's iPhone lags in closing the modal.