Skip to content

Commit 7f47062

Browse files
authored
support RTL android (#914)
* Support RTL android adding RTL on android * add RTL android
1 parent 1690863 commit 7f47062

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

android/src/main/java/org/wonday/pdf/PdfManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public void setShowsHorizontalScrollIndicator(PdfView view, boolean value) {
9999
// NOOP on Android
100100
}
101101

102-
@Override
103-
public void setShowsVerticalScrollIndicator(PdfView view, boolean value) {
104-
// NOOP on Android
102+
@ReactProp(name = "enableRTL")
103+
public void setEnableRTL(PdfView view, boolean enableRTL) {
104+
pdfView.setEnableRTL(enableRTL);
105105
}
106106

107107
@ReactProp(name = "scrollEnabled")

android/src/main/java/org/wonday/pdf/PdfView.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
7777
private FitPolicy fitPolicy = FitPolicy.WIDTH;
7878
private boolean singlePage = false;
7979
private boolean scrollEnabled = true;
80+
private boolean enableRTL = false;
8081

8182
private float originalWidth = 0;
8283
private float lastPageWidth = 0;
@@ -86,6 +87,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
8687
private int oldW = 0;
8788
private int oldH = 0;
8889

90+
private int totalPages = 0;
91+
private int[] pagesArrays;
92+
private int bookmarks = 0;
93+
8994
public PdfView(Context context, AttributeSet set){
9095
super(context, set);
9196
}
@@ -282,7 +287,34 @@ protected void onAttachedToWindow() {
282287

283288
public void drawPdf() {
284289
showLog(format("drawPdf path:%s %s", this.path, this.page));
285-
290+
File file = new File(this.path);
291+
292+
if (file.exists()) {
293+
try {
294+
ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
295+
PdfRenderer pdfRenderer = new PdfRenderer(fileDescriptor);
296+
this.totalPages = pdfRenderer.getPageCount();
297+
int[] pagesArrays = new int[this.totalPages];
298+
if (this.enableRTL) {
299+
if(this.page>0){
300+
this.page= this.bookmarks-1;
301+
}else{
302+
this.page=this.totalPages;
303+
}
304+
for (int i = totalPages-1; i>=0; i--) {
305+
pagesArrays[i] =totalPages-1- i;
306+
}
307+
this.pagesArrays = pagesArrays;
308+
309+
}else{
310+
this.pagesArrays = null;
311+
this.page=this.bookmarks-1;
312+
}
313+
} catch (IOException e) {
314+
Log.e("error", "error read PDF", e);
315+
}
316+
}
317+
286318
if (this.path != null){
287319

288320
// set scale
@@ -308,7 +340,9 @@ public void drawPdf() {
308340
configurator = this.fromUri(getURI(this.path));
309341
}
310342

311-
configurator.defaultPage(this.page-1)
343+
configurator
344+
.pages(this.pagesArrays)
345+
.defaultPage(this.page)
312346
.swipeHorizontal(this.horizontal)
313347
.onPageChange(this)
314348
.onLoad(this)
@@ -348,9 +382,15 @@ public void setPath(String path) {
348382

349383
// page start from 1
350384
public void setPage(int page) {
351-
this.page = page>1?page:1;
385+
this.page = page;
386+
this.bookmarks = page;
352387
}
353388

389+
public void setEnableRTL(boolean enableRTL){
390+
this.enableRTL= enableRTL;
391+
392+
}
393+
354394
public void setScale(float scale) {
355395
this.scale = scale;
356396
}

0 commit comments

Comments
 (0)