react-native-pdf icon indicating copy to clipboard operation
react-native-pdf copied to clipboard

Android App Crash with react-native-pdf v6.7.7 after upgrading to Expo SDK 53 (RN 0.79.2 / React 19)

Open Stan-1904 opened this issue 1 year ago • 1 comments

`import React, { useState, useRef } from 'react'; import { Modal, View, Platform, Alert, StyleSheet } from 'react-native'; import { Asset } from 'expo-asset'; import * as FileSystem from 'expo-file-system'; import Pdf from 'react-native-pdf'; // <-- Import causes issues when used import { Text, IconButton, Button } from 'react-native-paper';

// ... component setup, state, styles etc.

const openPdf = async (pdfModule) => { try { const asset = Asset.fromModule(pdfModule); await asset.downloadAsync(); const localUri = asset.localUri || asset.uri; let uriToLoad = localUri; // Handle content URI for Android if (Platform.OS === 'android' && localUri?.startsWith('file://')) { uriToLoad = await FileSystem.getContentUriAsync(localUri); } setSelectedPdfUri(uriToLoad); setModalVisible(true); // Reset page state... } catch (error) { console.error('Error loading PDF:', error); Alert.alert('Error', 'Could not load PDF.'); } };

// ... inside the component's return statement ...

<Modal animationType="slide" transparent={false} visible={modalVisible} onRequestClose={closePdf}

{selectedPdfUri ? ( <> {/* --- This component seems to cause the crash --- */} setTotalPages(numberOfPages)} onPageChanged={(page, numberOfPages) => { setCurrentPage(page); setTotalPages(numberOfPages); }} onError={(error) => { console.error('PDF Error: ', error); Alert.alert('Error', 'Could not display PDF.'); }} /> {/* --------------------------------------------- */} ) : ( Loading PDF... )} {/* PDF Controls (Bottom Bar) */} {/* ... Buttons for navigation and closing ... */} {/* Page selection dialog if needed */} `

Stan-1904 avatar May 03 '25 09:05 Stan-1904

The app is working again now. I installed the library react-native-blob-util.

Stan-1904 avatar May 04 '25 09:05 Stan-1904