Skip to content

Instantly share code, notes, and snippets.

@vshkl
Last active December 11, 2025 20:16
Show Gist options
  • Select an option

  • Save vshkl/449011238695cd444140ee49ac45af99 to your computer and use it in GitHub Desktop.

Select an option

Save vshkl/449011238695cd444140ee49ac45af99 to your computer and use it in GitHub Desktop.
Android. java.lang.IllegalStateException: Already closed. Mix of `react-native-pdf` and `react-native-pdf-jsi`.
diff --git a/android/src/main/java/org/wonday/pdf/PdfManager.java b/android/src/main/java/org/wonday/pdf/PdfManager.java
index 03e6de2fd385b833223d90375423e0b323bb5fff..dcc4e4395aff116a999f15bf53690ed1286eccd4 100644
--- a/android/src/main/java/org/wonday/pdf/PdfManager.java
+++ b/android/src/main/java/org/wonday/pdf/PdfManager.java
@@ -60,7 +60,7 @@ public class PdfManager extends SimpleViewManager<PdfView> implements RNPDFPdfVi
@Override
public void onDropViewInstance(PdfView pdfView) {
- pdfView = null;
+ this.pdfView = null;
}
@ReactProp(name = "path")
diff --git a/android/src/main/java/org/wonday/pdf/PdfView.java b/android/src/main/java/org/wonday/pdf/PdfView.java
index 91685076a4207245b9537208d9706c75d1531753..8ff57a0b7c8bb3dab9cfcf27498d8a06960b5f9e 100644
--- a/android/src/main/java/org/wonday/pdf/PdfView.java
+++ b/android/src/main/java/org/wonday/pdf/PdfView.java
@@ -89,6 +89,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
private int oldW = 0;
private int oldH = 0;
+ private String lastLoadedPath = null;
+ private boolean needsReload = true;
+
public PdfView(Context context, AttributeSet set){
super(context, set);
}
@@ -294,6 +298,16 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
}
public void drawPdf() {
+ if (!needsReload && this.path != null && this.path.equals(lastLoadedPath)) {
+ if (this.page > 0 && !this.isRecycled()) {
+ this.jumpTo(this.page - 1, false);
+ }
+ return;
+ }
+
showLog(format("drawPdf path:%s %s", this.path, this.page));
if (this.path != null){
@@ -365,6 +379,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
}
configurator.load();
+
+ lastLoadedPath = this.path;
+ needsReload = false;
}
}
@@ -373,13 +391,22 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
}
public void setPath(String path) {
+ if (path == null || !path.equals(this.path)) {
+ needsReload = true;
+ }
this.path = path;
}
// page start from 1
public void setPage(int page) {
- this.page = Math.max(page, 1);
- this.handlePage(this.page - 1);
+ int newPage = Math.max(page, 1);
+ int oldPage = this.page;
+ this.page = newPage;
+
+ if (newPage != oldPage && !needsReload && this.path != null && !this.isRecycled()) {
+ this.jumpTo(newPage - 1, false);
+ }
}
public void setEnableRTL(boolean enableRTL) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment