Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landscape View cripples for whole App after PDF file is opened #858

Open
akashmkj027 opened this issue Aug 7, 2024 · 0 comments
Open

Landscape View cripples for whole App after PDF file is opened #858

akashmkj027 opened this issue Aug 7, 2024 · 0 comments

Comments

@akashmkj027
Copy link

"react-native": "0.63.3",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.9.4",
"react-navigation-tabs": "^2.5.6",

"react-native-pdf": "6.6.2",

ios and android both (devices which have notch)

Before opening PDF file my landscape and portrait orientation for the app works perfectly. It can be seen in the attached video in first 5-10 seconds. But after i open the pdf file and navigate to go back. My entire application is disaligned when rotates to Landscape. SafeAreaView doesn't work, and application is overflowing from the notch area (check last 5-10 sec of the video).

Screen.Recording.2024-08-07.at.12.40.58.PM.mp4
import React, {useState, useEffect} from 'react';
import axios from 'axios';
import {
  StyleSheet,
  Dimensions,
  View,
  Text,
  ActivityIndicator
} from 'react-native';
import {baseUrl} from '../../config/baseUrl';
import isEmpty from 'lodash/isEmpty';
import Pdf from 'react-native-pdf';
import 'react-native-get-random-values';
import {decryptData} from '../../config/EncryptDecrypt';
import { deleteTempFilePath } from '../../config/fileStoreStructure';

export const PDFViewRender = ({
  data,
  offlineFilePath,
  decryptionKeys,
  fileExtension,
  onSuccessOpenDocuments,
}) => {
  const [errorMsg, setErrorMessage] = useState('');
  const [sourceUrl, setSourceUrl] = useState('');
  const [loader, setLoader] = useState(true);
  const token = axios.defaults.headers.common.Authorization;

  useEffect(() => {
    url();
    return () => {deleteTempFilePath ();}
  }, [data]);

  const decryptFile = async () => {
    let path = await decryptData(offlineFilePath, decryptionKeys,`${data.DocumentID}`,fileExtension);
    setSourceUrl({
      uri : path,
      cache: true,
    });
  };

  const url = async () => {
    if (offlineFilePath) {
      await decryptFile();
    } else {
      setSourceUrl({
        uri:
          baseUrl + '/sg2/api/v1.0/mdocs/document/download/' + data.DocumentID,
        cache: true,
        method: 'GET',
        headers: {Authorization: token, responseType: 'arraybuffer'},
      });
    }
    setLoader(false);
  };

  const loadingComponent = () => (
    <View style={styles.msgContainer}>
      <ActivityIndicator size="large" color="#0000ff" />
    </View>
  );

  return (
    <View style={styles.container}>
      {loader ? (
        loadingComponent()
      ) : isEmpty(errorMsg) && sourceUrl ? (
        <Pdf
          source={sourceUrl}
          style={styles.pdf}
          trustAllCerts={false}
          maxScale={10}
          minScale={1}
          onLoadComplete={(numberOfPages, filePath) => {
            onSuccessOpenDocuments();
          }}
          renderActivityIndicator={(progress) => {
            return loadingComponent();
          }}
          horizontal={true}
          onError={(error) => {
            setErrorMessage(error.message);
          }}
        />
      ) : (
        <View style={styles.msgContainer}>
          <Text>{errorMsg}</Text>
        </View>
      )}
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    alignItems: 'center',
    marginTop: 25,
  },
  pdf: {
    flex: 1,
    width: Dimensions.get('window').width,
    height: Dimensions.get('window').height,
  },
  msgContainer: {
    justifyContent: 'center',
    height: '100%',
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant