setPage() method isn't working
when I try to set page the app doesn't change the page
+1
+1
I made a patch file that fixes this issue also referenced in issue #817
patches/react-native-pdf+6.7.7.patch
--- a/node_modules/react-native-pdf/android/src/main/java/org/wonday/pdf/PdfView.java
+++ b/node_modules/react-native-pdf/android/src/main/java/org/wonday/pdf/PdfView.java
@@ -12,6 +12,8 @@ import java.io.File;
import android.content.ContentResolver;
import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
import android.util.SizeF;
import android.view.View;
import android.view.ViewGroup;
@@ -157,7 +159,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
TopChangeEvent tce = new TopChangeEvent(surfaceId, getId(), event);
if (dispatcher != null) {
- dispatcher.dispatchEvent(tce);
+ new Handler(Looper.getMainLooper()).postDelayed(() -> dispatcher.dispatchEvent(tce), 10);
}
// ReactContext reactContext = (ReactContext)this.getContext();
// reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
@@ -347,6 +349,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
// page start from 1
public void setPage(int page) {
this.page = page>1?page:1;
+ this.jumpTo(this.page - 1); // Subtract 1 because PDFView uses 0-based page numbers
}
public void setScale(float scale) {
You'll need to install patch-package and add "postinstall": "patch-package" to your scripts section in package.json.
Then it works for me best of luck!
+1
+1
public void setPage(int page) {
this.jumpTo(page-1);
}
"postinstall": "patch-package"
dude you crazy it works now thank you in advanced you saved my whole project
I made a patch file that fixes this issue also referenced in issue #817
patches/react-native-pdf+6.7.7.patch
--- a/node_modules/react-native-pdf/android/src/main/java/org/wonday/pdf/PdfView.java +++ b/node_modules/react-native-pdf/android/src/main/java/org/wonday/pdf/PdfView.java @@ -12,6 +12,8 @@ import java.io.File; import android.content.ContentResolver; import android.content.Context; +import android.os.Handler; +import android.os.Looper; import android.util.SizeF; import android.view.View; import android.view.ViewGroup; @@ -157,7 +159,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl TopChangeEvent tce = new TopChangeEvent(surfaceId, getId(), event); if (dispatcher != null) { - dispatcher.dispatchEvent(tce); + new Handler(Looper.getMainLooper()).postDelayed(() -> dispatcher.dispatchEvent(tce), 10); } // ReactContext reactContext = (ReactContext)this.getContext(); // reactContext.getJSModule(RCTEventEmitter.class).receiveEvent( @@ -347,6 +349,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl // page start from 1 public void setPage(int page) { this.page = page>1?page:1; + this.jumpTo(this.page - 1); // Subtract 1 because PDFView uses 0-based page numbers } public void setScale(float scale) {You'll need to install
patch-packageand add"postinstall": "patch-package"to your scripts section inpackage.json.
For those using pnpm, use:
pnpm patch react-native-pdf@<your-version>
then
pnpm patch-commit <path-generated-by-the-command-above>
I solved all my Android problems with this, thanks guys! Not the ideal solution, but 1 less issue today lol