wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.6k stars 557 forks source link

Android crash when navigating to and from document #865

Open IanKirkham opened 2 months ago

IanKirkham commented 2 months ago

What react-native version are you using? 0.75.2

What react-native-pdf version are you using? 6.7.5

What platform does your issue occur on? (android/ios/both) android

Describe your issue as precisely as possible : Issue is occurring on 6.7.5 but not reproducible on 6.7.4. Repro:

  1. Create new react native app with react-native-pdf and react-navigation boilerplate
  2. Navigate to and from document screen multiple times
  3. Observe application will crash

Join a screenshot or video of the problem on the simulator or device?

v6.7.4 v6.7.5
video video

Show us the code you are using?

// App.tsx
import * as React from 'react';
import {Button, View, Text} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import PDFExample from './PdfViewer';

function HomeScreen({navigation}) {
  return (
    <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
      <Text>Home Screen</Text>
      <Button
        title="Go to Details"
        onPress={() => navigation.navigate('Details')}
      />
    </View>
  );
}

function DetailsScreen() {
  return <PDFExample />;
}

const Stack = createNativeStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Home">
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

// PdfViewer.tsx
import React from 'react';
import {StyleSheet, Dimensions, View} from 'react-native';
import Pdf from 'react-native-pdf';

export default class PDFExample extends React.Component {
  render() {
    const source = {
      uri: 'http://samples.leanpub.com/thereactnativebook-sample.pdf',
      cache: true,
    };

    return (
      <View style={styles.container}>
        <Pdf
          source={source}
          trustAllCerts={false}
          onLoadComplete={(numberOfPages, filePath) => {
            console.log(`Number of pages: ${numberOfPages}`);
          }}
          onPageChanged={(page, numberOfPages) => {
            console.log(`Current page: ${page}`);
          }}
          onError={error => {
            console.log(error);
          }}
          onPressLink={uri => {
            console.log(`Link pressed: ${uri}`);
          }}
          style={styles.pdf}
        />
      </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,
  },
});
omarabualhija commented 2 months ago

same issue, any update !