Android Crash on setState
What react-native version are you using?
0.57.7
What react-native-pdf version are you using?
5.0.11
What platform does your issue occur on? (android/ios/both)
android
Describe your issue as precisely as possible :
Whenever i change the source of the PDF or hide the PDF View via setState, my android app crashes with the following error:
12-30 22:21:19.959 14568 14568 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.github.barteksc.pdfviewer.PdfFile.getPageAtOffset(float, float)' on a null object reference
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at com.github.barteksc.pdfviewer.DragPinchManager.checkLinkTapped(DragPinchManager.java:88)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at com.github.barteksc.pdfviewer.DragPinchManager.onSingleTapConfirmed(DragPinchManager.java:69)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:312)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6940)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
12-30 22:21:19.959 14568 14568 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Facing this issue since last 2 months. Any solution??
the problem is in AndroidPdfViewer but the PR that would be fixing this is open since 3 months: https://github.com/barteksc/AndroidPdfViewer/pull/638
In my case the problem was that react-native-pdf is using pdf-viewer:3.1.0-beta.1 witch apparently is not stable, defined in:
node_modules/react-native-pdf/android/build.gradle
dependencies {
implementation "com.facebook.react:react-native:${_reactNativeVersion}"
implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
implementation 'com.google.code.gson:gson:2.8.5'
}
I did override the implementation with android-pdf-viewer:3.+ in this file: android/app/build.gradle
dependencies {
. . .
implementation 'com.github.barteksc:android-pdf-viewer:3.+'
. . .
}
hope this helps
Can we update the dependency version to fix this issue? Opened a PR: https://github.com/wonday/react-native-pdf/pull/489