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

Android crash when navigating to and from document #865

Open
IanKirkham opened this issue Sep 9, 2024 · 2 comments
Open

Android crash when navigating to and from document #865

IanKirkham opened this issue Sep 9, 2024 · 2 comments

Comments

@IanKirkham
Copy link

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
Copy link

same issue, any update !

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

3 participants
@IanKirkham @omarabualhija and others