wonday / react-native-pdf

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

Android Crash at PDF viewing #833

Open santiagogarzon opened 6 months ago

santiagogarzon commented 6 months ago

What react-native version are you using? 0.73.6 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 : 1) Steps to reproduce the issue or to explain in which case you get the issue 2) Interesting logs

just using PDF component on Android crash the app.

LOGS:

Instabug Caught an Unhandled Exception: java.lang.NoClassDefFoundError
                                                                                                    java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/enums/EnumEntriesKt;
                                                                                                        at io.legere.pdfiumandroid.util.AlreadyClosedBehavior.<clinit>(Config.kt:9)
                                                                                                        at io.legere.pdfiumandroid.util.Config.<init>(Config.kt:14)
                                                                                                        at io.legere.pdfiumandroid.util.Config.<init>(Unknown Source:2)
                                                                                                        at com.github.barteksc.pdfviewer.PDFView.<init>(PDFView.java:314)
                                                                                                        at org.wonday.pdf.PdfView.<init>(PdfView.java:85)
                                                                                                        at org.wonday.pdf.PdfManager.createViewInstance(PdfManager.java:57)
                                                                                                        at org.wonday.pdf.PdfManager.createViewInstance(PdfManager.java:28)
                                                                                                        at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:176)
                                                                                                        at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:108)
                                                                                                        at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:281)
                                                                                                        at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:194)
                                                                                                        at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:920)
                                                                                                        at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1037)
                                                                                                        at com.facebook.react.uimanager.UIViewOperationQueue.-$$Nest$mflushPendingBatches(Unknown Source:0)
                                                                                                        at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1097)
                                                                                                        at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
                                                                                                        at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
                                                                                                        at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
                                                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1035)
                                                                                                        at android.view.Choreographer.doCallbacks(Choreographer.java:845)
                                                                                                        at android.view.Choreographer.doFrame(Choreographer.java:775)
                                                                                                        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1022)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                        at android.os.Looper.loop(Looper.java:288)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7839)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

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

Show us the code you are using?

<Pdf
                        style={flex}
                        renderActivityIndicator={(): ReactElement => <Spinner image={SpinnerImage.BLUE_SPINNER} isVisible={true} />}
                        source={source}
                        onError={(): void => setError(true)}
                        trustAllCerts={false}
                    />
ishaqashraf commented 6 months ago

same +1

tranhoang1010vn commented 5 months ago

same +1

JoaSebas commented 4 months ago

+1

HamidAbdullah commented 4 months ago

image

same issue ? {pdfUrl ? ( <Pdf ref={pdfRef} source={{ uri: pdfUrl, cache: true, cacheFileName: QuranCompletePdf, }} onLoadComplete={handleLoadComplete} onPageChanged={handlePageChanged} onError={handleError} style={styles.pdf} /> ) : ( <LoadingIndicator loading={true} size={40} color={'#000'} /> )}

JoaSebas commented 4 months ago

The error was caused by the key. I created a dynamic key, but the library does not support this and re-rendered, which caused the app to crash and close. The solution was to create a unique key.

HamidAbdullah commented 4 months ago

Can you share the code?

JoaSebas commented 4 months ago

{pdfPath && (

Karanxidhu commented 3 months ago

@JoaSebas

<Pdf trustAllCerts={false} // key={pdfPath} source={source} style={{flex: 1, width: Dimensions.get('window').width*0.87 }} page={1} scale={1.0} minScale={0.5} maxScale={3.0} renderActivityIndicator={() => (

                                )}
                                enablePaging={true}
                                onLoadProgress={(percentage) => console.log(`Loading :${percentage}`)}
                                onLoadComplete={() => console.log('Loading Complete')}
                                onPageChanged={(page, totalPages) => console.log(`${page}/${totalPages}`)}
                                onError={(error) => console.log(error)}
                                onPageSingleTap={(page) => alert(page)}
                                onPressLink={(link) => Linking.openURL(link)}
                                onScaleChanged={(scale) => console.log(scale)}
                                // singlePage={true}
                                spacing={10}
                    />

can you help me as i might be doing something wrong idk, btw file source is a link

HamidAbdullah commented 3 months ago

Yes , Tell me what is the issue ?

On Fri, 9 Aug 2024 at 05:24, Karanjot Singh @.***> wrote:

@JoaSebas https://github.com/JoaSebas

<Pdf trustAllCerts={false} // key={pdfPath} source={source} style={{flex: 1, width: Dimensions.get('window').width*0.87 }} page={1} scale={1.0} minScale={0.5} maxScale={3.0} renderActivityIndicator={() => (

)} enablePaging={true} onLoadProgress={(percentage) => console.log(Loading :${percentage})} onLoadComplete={() => console.log('Loading Complete')} onPageChanged={(page, totalPages) => console.log(${page}/${totalPages})} onError={(error) => console.log(error)} onPageSingleTap={(page) => alert(page)} onPressLink={(link) => Linking.openURL(link)} onScaleChanged={(scale) => console.log(scale)} // singlePage={true} spacing={10} />

can you help me as i might be doing something wrong idk, btw file source is a link

— Reply to this email directly, view it on GitHub https://github.com/wonday/react-native-pdf/issues/833#issuecomment-2277827981, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3DFAZPYNTSPCOVQ3OT63WTZQSYH7AVCNFSM6AAAAABHNKAHAOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZXHAZDOOJYGE . You are receiving this because you commented.Message ID: @.***>

Karanxidhu commented 3 months ago

So i am trying to load a pdf, it starts crashes the app as soon as loading completes

JoaSebas commented 3 months ago

Don't comment the key, and agree validation that component is visible only if have a path, see my example. You can try setting the path is same key for the component.

Karanxidhu commented 3 months ago

@JoaSebas {pdf&&<Pdf source={source} key={pdf} 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={{ flex:1, width:Dimensions.get('window').width, height:Dimensions.get('window').height, }}/>}

                                this is current component but still crashes on load + i lowered the version to 6.7.1 
                                Tell me if i am still doing something wrong
wency-yang commented 2 months ago

@HamidAbdullah How is the crash going? Has it been resolved?

andrewhamili commented 1 month ago

image

Experiencing the same issue.