Skip to content
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

Add configuration for page mode and displaying the first page as a single page #227

Merged
merged 4 commits into from
May 28, 2019
Merged
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
34 changes: 31 additions & 3 deletions android/src/main/java/com/pspdfkit/react/ConfigurationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@

package com.pspdfkit.react;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.pspdfkit.configuration.activity.UserInterfaceViewMode;
import com.pspdfkit.configuration.activity.PdfActivityConfiguration;
import com.pspdfkit.configuration.activity.ThumbnailBarMode;
import com.pspdfkit.configuration.activity.UserInterfaceViewMode;
import com.pspdfkit.configuration.page.PageFitMode;
import com.pspdfkit.configuration.page.PageLayoutMode;
import com.pspdfkit.configuration.page.PageScrollDirection;
import com.pspdfkit.configuration.page.PageScrollMode;

Expand Down Expand Up @@ -58,7 +59,11 @@ public class ConfigurationAdapter {
private static final String SHOW_PRINT_ACTION = "showPrintAction";
private static final String SHOW_DOCUMENT_INFO_VIEW = "showDocumentInfoView";
private static final String SHOW_DOCUMENT_TITLE_OVERLAY = "documentLabelEnabled";

private static final String PAGE_MODE = "pageMode";
private static final String PAGE_MODE_SINGLE = "single";
private static final String PAGE_MODE_DOUBLE = "double";
private static final String PAGE_MODE_AUTO = "automatic";
private static final String FIRST_PAGE_ALWAYS_SINGLE = "firstPageAlwaysSingle";

private final PdfActivityConfiguration.Builder configuration;

Expand Down Expand Up @@ -134,6 +139,12 @@ public ConfigurationAdapter(@NonNull Context context, ReadableMap configuration)
if (configuration.hasKey(SHOW_DOCUMENT_TITLE_OVERLAY)) {
configureShowDocumentTitleOverlay(configuration.getBoolean(SHOW_DOCUMENT_TITLE_OVERLAY));
}
if (configuration.hasKey(PAGE_MODE)) {
configurePageMode(configuration.getString(PAGE_MODE));
}
if (configuration.hasKey(FIRST_PAGE_ALWAYS_SINGLE)) {
configureFirstPageAlwaysSingle(configuration.getBoolean(FIRST_PAGE_ALWAYS_SINGLE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default of configuration.getBoolean(...). What does it return if the value that was set is not a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not a boolean an exception is thrown, this makes sense in my opinion so users know if they passed an invalid value in the JS code.

}
}
}

Expand Down Expand Up @@ -294,6 +305,23 @@ private void configureShowDocumentTitleOverlay(boolean showDocumentTitleOverlay)
}
}

private void configurePageMode(@Nullable final String pageMode) {
PageLayoutMode pageLayoutMode = PageLayoutMode.AUTO;
if (pageMode == null ||
pageMode.equalsIgnoreCase(PAGE_MODE_AUTO)) {
pageLayoutMode = PageLayoutMode.AUTO;
} else if (pageMode.equalsIgnoreCase(PAGE_MODE_SINGLE)) {
pageLayoutMode = PageLayoutMode.SINGLE;
} else if (pageMode.equalsIgnoreCase(PAGE_MODE_DOUBLE)) {
pageLayoutMode = PageLayoutMode.DOUBLE;
}
configuration.layoutMode(pageLayoutMode);
}

private void configureFirstPageAlwaysSingle(final boolean firstPageAlwaysSingle) {
configuration.firstPageAlwaysSingle(firstPageAlwaysSingle);
}

public PdfActivityConfiguration build() {
return configuration.build();
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-pspdfkit",
"version": "1.23.14",
"version": "1.23.15",
"description": "A React Native module for the PSPDFKit library.",
"keywords": [
"react native",
Expand Down
2 changes: 1 addition & 1 deletion samples/Catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Catalog",
"version": "1.23.14",
"version": "1.23.15",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
Expand Down