I have a react native app which is a chat application and users can share files and images with each other on chat, on clicking the file, the file opens in native view on top of the app, and since the app orientation is locked to potrait, the pdf does not rotate.
I tried to follow the native solution in this link - Only ONE VIEW landscape mode
but I cannot find in the code where the native view is being initialised.. Looking for help with this.
PS. I need the app orientation to be locked to portrait and want portait and landscape in os native pdf viewer.
Using react-navigation for navigation and rn-fetch-blob for downloading (from firebase storage) and file access.
async function donwloadFile(props) {
let token = await getAuthToken();
let hasPermission = await requestFilePermissions(() => {}, props.type);
if (!hasPermission) {
// ask for permission
return;
}
const { dirs } = RNFetchBlob.fs;
const fileName = props.currentMessage.fileReference || props.currentMessage.fileName;
const filePath =
Platform.OS === 'android'
? `${dirs.DownloadDir}/OrangeHealth/${props.threadId}/${fileName}`
: `${dirs.DocumentDir}/OrangeHealth/${props.threadId}/${fileName}`;
RNFetchBlob.fs.exists(filePath).then((res) => {
// checks if file is already present
if (res) {
if (Platform.OS === 'android') {
RNFetchBlob.android
.actionViewIntent(filePath, props.currentMessage.formatType)
.then(() => {
console.log('File opened');
})
.catch((e) => {
toastAlertMessage('Unable to open file');
});
} else {
RNFetchBlob.ios.openDocument(filePath);
}
} else {
RNFetchBlob.config({
fileCache: false,
path: filePath,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
mediaScannable: true,
title: props.currentMessage.fileName,
path: filePath,
},
})
.fetch('GET', props.currentMessage.file, {
Authorization: `Bearer ${token}`,
})
.then(() => {
setIsDownloading(false);
if (Platform.OS === 'android') {
RNFetchBlob.android
.actionViewIntent(
filePath,
props.currentMessage.formatType
)
.catch(() => {
console.log('unable to open file')
});
} else {
RNFetchBlob.ios.openDocument(filePath);
}
})
.catch((e) => {
console.log('error ', e);
});
}
});
}