Skip to content

support RTL android #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/src/main/java/org/wonday/pdf/PdfManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public void setShowsHorizontalScrollIndicator(PdfView view, boolean value) {
// NOOP on Android
}

@Override
public void setShowsVerticalScrollIndicator(PdfView view, boolean value) {
// NOOP on Android
@ReactProp(name = "enableRTL")
public void setEnableRTL(PdfView view, boolean enableRTL) {
pdfView.setEnableRTL(enableRTL);
}

@ReactProp(name = "scrollEnabled")
Expand Down
48 changes: 44 additions & 4 deletions android/src/main/java/org/wonday/pdf/PdfView.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
private FitPolicy fitPolicy = FitPolicy.WIDTH;
private boolean singlePage = false;
private boolean scrollEnabled = true;
private boolean enableRTL = false;

private float originalWidth = 0;
private float lastPageWidth = 0;
Expand All @@ -84,6 +85,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
private int oldW = 0;
private int oldH = 0;

private int totalPages = 0;
private int[] pagesArrays;
private int bookmarks = 0;

public PdfView(Context context, AttributeSet set){
super(context, set);
}
Expand Down Expand Up @@ -280,7 +285,34 @@ protected void onAttachedToWindow() {

public void drawPdf() {
showLog(format("drawPdf path:%s %s", this.path, this.page));

File file = new File(this.path);

if (file.exists()) {
try {
ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
PdfRenderer pdfRenderer = new PdfRenderer(fileDescriptor);
this.totalPages = pdfRenderer.getPageCount();
int[] pagesArrays = new int[this.totalPages];
if (this.enableRTL) {
if(this.page>0){
this.page= this.bookmarks-1;
}else{
this.page=this.totalPages;
}
for (int i = totalPages-1; i>=0; i--) {
pagesArrays[i] =totalPages-1- i;
}
this.pagesArrays = pagesArrays;

}else{
this.pagesArrays = null;
this.page=this.bookmarks-1;
}
} catch (IOException e) {
Log.e("error", "error read PDF", e);
}
}

if (this.path != null){

// set scale
Expand All @@ -306,7 +338,9 @@ public void drawPdf() {
configurator = this.fromUri(getURI(this.path));
}

configurator.defaultPage(this.page-1)
configurator
.pages(this.pagesArrays)
.defaultPage(this.page)
.swipeHorizontal(this.horizontal)
.onPageChange(this)
.onLoad(this)
Expand Down Expand Up @@ -346,9 +380,15 @@ public void setPath(String path) {

// page start from 1
public void setPage(int page) {
this.page = page>1?page:1;
this.page = page;
this.bookmarks = page;
}

public void setEnableRTL(boolean enableRTL){
this.enableRTL= enableRTL;

}

public void setScale(float scale) {
this.scale = scale;
}
Expand Down Expand Up @@ -502,4 +542,4 @@ public boolean onTouch(View v, MotionEvent event) {
}
}
}
}
}