Skip to content

Commit

Permalink
Release 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PSPDFKit committed Jun 5, 2023
1 parent f823d8b commit 049ac9d
Show file tree
Hide file tree
Showing 62 changed files with 3,403 additions and 2,714 deletions.
794 changes: 386 additions & 408 deletions ACKNOWLEDGEMENTS.md

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
## Newest Release

### 2.5.2 - 13 Apr 2023
- Fixes missing RXJava dependencies for Android. (#39813)
### 2.6.0 - 05 Jun 2023
- Adds measurement tools configurations (#40296)
- Updates for PSPDFKit 8.7.2 for Android. (#40697)
- Updates for PSPDFKit 12.2 for iOS. (#40697)
- Fixes annotation tools subgroups selection with menuItem grouping customization (#40593)

## Previous Releases

### 2.5.2 - 13 Apr 2023
- Fixes missing RXJava dependencies for Android. (#39813)

### 2.5.1 - 03 Apr 2023
- Updated NativeCatalog configuration and replaced deprecated AppDelegate.m
- Bumps PSPDFKit for Android version to 8.6.0
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Contains gradle configuration constants
*/
ext {
PSPDFKIT_VERSION = '8.6.0'
PSPDFKIT_VERSION = '8.7.2'
}

buildscript {
Expand Down
58 changes: 46 additions & 12 deletions android/src/main/java/com/pspdfkit/react/ConfigurationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.pspdfkit.configuration.page.PageScrollMode;
import com.pspdfkit.configuration.sharing.ShareFeatures;
import com.pspdfkit.configuration.signatures.SignatureSavingStrategy;
import com.pspdfkit.preferences.PSPDFKitPreferences;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -108,6 +109,11 @@ public class ConfigurationAdapter {
private static final String SHOW_ANNOTATION_LIST_ACTION = "showAnnotationListAction";
private static final String ANNOTATION_EDITING_ENABLED = "enableAnnotationEditing";

// Measurement tools options
private static final String ENABLED_MEASUREMENT_TOOLS = "enableMeasurementTools";
private static final String ENABLE_MAGNIFIER = "enableMagnifier";
private static final String ENABLED_MEASUREMENT_TOOL_SNAPPING = "enableMeasurementToolSnapping";

// Deprecated Options
/**
* @deprecated This key word was deprecated with PSPDFKit for React Native 2.1.
Expand Down Expand Up @@ -152,6 +158,7 @@ public ConfigurationAdapter(@NonNull final Context context, ReadableMap configur
ReadableMapKeySetIterator iterator = configuration.keySetIterator();
boolean hasConfiguration = iterator.hasNextKey();
this.configuration = new PdfActivityConfiguration.Builder(context);
this.configuration.disableContentEditing();
if (hasConfiguration) {
String key;

Expand Down Expand Up @@ -303,6 +310,18 @@ public ConfigurationAdapter(@NonNull final Context context, ReadableMap configur
if (key != null) {
configureToolbarTitle(configuration.getString(key));
}
key = getKeyOrNull(configuration, ENABLE_MAGNIFIER);
if (key != null) {
configureMagnifierEnabled(configuration.getBoolean(key));
}
key = getKeyOrNull(configuration, ENABLED_MEASUREMENT_TOOLS);
if (key != null) {
configureMeasurementToolsEnabled(configuration.getBoolean(key));
}
key = getKeyOrNull(configuration, ENABLED_MEASUREMENT_TOOL_SNAPPING);
if (key != null) {
configureMeasurementToolSnappingEnabled(context, configuration.getBoolean(key));
}
}
}

Expand Down Expand Up @@ -427,18 +446,21 @@ private void configureShowThumbnailBar(@Nullable final String showThumbnailBar)
return;
}

if (showThumbnailBar.equals(SHOW_THUMBNAIL_BAR_NONE)) {
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_NONE);
} else if (showThumbnailBar.equals(SHOW_THUMBNAIL_BAR_DEFAULT)) {
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_FLOATING);
} else if (showThumbnailBar.equals(SHOW_THUMBNAIL_BAR_FLOATING)) {
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_FLOATING);
} else if (showThumbnailBar.equals(SHOW_THUMBNAIL_BAR_SCRUBBERBAR)) {
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_PINNED);
} else if (showThumbnailBar.equals(SHOW_THUMBNAIL_BAR_PINNED)) {
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_PINNED);
} else if (showThumbnailBar.equals(SHOW_THUMBNAIL_BAR_SCROLLABLE)) {
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_SCROLLABLE);
switch (showThumbnailBar) {
case SHOW_THUMBNAIL_BAR_NONE:
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_NONE);
break;
case SHOW_THUMBNAIL_BAR_DEFAULT:
case SHOW_THUMBNAIL_BAR_FLOATING:
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_FLOATING);
break;
case SHOW_THUMBNAIL_BAR_SCRUBBERBAR:
case SHOW_THUMBNAIL_BAR_PINNED:
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_PINNED);
break;
case SHOW_THUMBNAIL_BAR_SCROLLABLE:
configuration.setThumbnailBarMode(ThumbnailBarMode.THUMBNAIL_BAR_MODE_SCROLLABLE);
break;
}
}

Expand Down Expand Up @@ -613,6 +635,18 @@ private void configureToolbarTitle(@Nullable final String customTitle) {
configuration.title(customTitle);
}

private void configureMeasurementToolsEnabled(final Boolean measurementToolsEnabled) {
configuration.setMeasurementToolsEnabled(measurementToolsEnabled);
}

private void configureMagnifierEnabled(final Boolean magnifierEnabled) {
configuration.enableMagnifier(magnifierEnabled);
}

private void configureMeasurementToolSnappingEnabled(Context context, final Boolean snappingEnabled) {
PSPDFKitPreferences.get(context).setMeasurementSnappingEnabled(snappingEnabled);
}

public PdfActivityConfiguration build() {
return configuration.build();
}
Expand Down
72 changes: 67 additions & 5 deletions android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
import com.pspdfkit.PSPDFKit;
import com.pspdfkit.annotations.Annotation;
import com.pspdfkit.annotations.AnnotationType;
import com.pspdfkit.annotations.measurements.FloatPrecision;
import com.pspdfkit.annotations.measurements.Scale;
import com.pspdfkit.document.PdfDocument;
import com.pspdfkit.document.PdfDocumentLoader;
import com.pspdfkit.document.image.CameraImagePickerFragment;
import com.pspdfkit.document.image.GalleryImagePickerFragment;
import com.pspdfkit.document.processor.PdfProcessor;
import com.pspdfkit.document.processor.PdfProcessorTask;
import com.pspdfkit.exceptions.InvalidPSPDFKitLicenseException;
import com.pspdfkit.react.RNInstantPdfActivity;
import com.pspdfkit.listeners.SimpleDocumentListener;
import com.pspdfkit.react.helper.ConversionHelpers;
Expand All @@ -52,7 +55,6 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import com.pspdfkit.exceptions.InvalidPSPDFKitLicenseException;

public class PSPDFKitModule extends ReactContextBaseJavaModule implements Application.ActivityLifecycleCallbacks, ActivityEventListener {

Expand Down Expand Up @@ -144,7 +146,7 @@ public void presentPdf(@NonNull String document, @NonNull ReadableMap configurat
PdfActivity.showDocument(getCurrentActivity(), Uri.parse(document), configurationAdapter.build());
}
}

@ReactMethod
public void presentImage(@NonNull String imageDocument, @NonNull ReadableMap configuration, @Nullable Promise promise) {
if (getCurrentActivity() != null) {
Expand Down Expand Up @@ -238,7 +240,7 @@ public void processAnnotations(@NonNull final String processingMode,
@NonNull final String sourceDocumentPath,
@NonNull final String targetDocumentPath,
@NonNull final Promise promise) {

// This is an edge case where file scheme is missing.
String documentPath = Uri.parse(sourceDocumentPath).getScheme() == null
? FILE_SCHEME + sourceDocumentPath : sourceDocumentPath;
Expand All @@ -261,6 +263,66 @@ public void processAnnotations(@NonNull final String processingMode,
});
}

@ReactMethod
public void setMeasurementScale(@Nullable final Scale scale) {
if (resumedActivity instanceof PdfActivity) {
final PdfActivity activity = (PdfActivity) resumedActivity;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
PdfDocument document = activity.getDocument();
if (document != null && scale != null) {
document.setMeasurementScale(scale);
} else {
activity.getPdfFragment().addDocumentListener(new SimpleDocumentListener() {
@Override
public void onDocumentLoaded(@NonNull PdfDocument document) {
activity.getPdfFragment().removeDocumentListener(this);
}
});
}
}
});
} else {
onPdfActivityOpenedTask = new Runnable() {
@Override
public void run() {
setMeasurementScale(scale);
}
};
}
}
@ReactMethod
public void setMeasurementPrecision(@Nullable final FloatPrecision floatPrecision) {
if (resumedActivity instanceof PdfActivity) {
final PdfActivity activity = (PdfActivity) resumedActivity;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
PdfDocument document = activity.getDocument();
FloatPrecision precision = floatPrecision;
if (document != null && precision != null) {
document.setMeasurementPrecision(precision);
} else {
activity.getPdfFragment().addDocumentListener(new SimpleDocumentListener() {
@Override
public void onDocumentLoaded(@NonNull PdfDocument document) {
activity.getPdfFragment().removeDocumentListener(this);
}
});
}
}
});
} else {
onPdfActivityOpenedTask = new Runnable() {
@Override
public void run() {
setMeasurementPrecision(floatPrecision);
}
};
}
}

private static PdfProcessorTask.AnnotationProcessingMode getProcessingModeFromString(@NonNull final String mode) {
if ("print".equalsIgnoreCase(mode)) {
return PdfProcessorTask.AnnotationProcessingMode.PRINT;
Expand Down Expand Up @@ -300,7 +362,7 @@ public synchronized void onActivityResumed(Activity activity) {
// Run our queued up task when a PdfActivity is displayed.
onPdfActivityOpenedTask.run();
onPdfActivityOpenedTask = null;

// We notify the called as soon as the document is loaded or loading failed.
if (lastPresentPromise != null) {
PdfActivity pdfActivity = (PdfActivity) resumedActivity;
Expand Down Expand Up @@ -389,7 +451,7 @@ public void onNewIntent(Intent intent) {
private boolean isPdf(File file) {
return file.getName().toLowerCase().endsWith(".pdf");
}

private boolean isImage(File file) {
for (String extension: SUPPORTED_IMAGE_TYPES) {
if (file.getName().toLowerCase().endsWith(extension)) {
Expand Down
45 changes: 32 additions & 13 deletions android/src/main/java/com/pspdfkit/react/ReactPdfViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@
import com.pspdfkit.react.menu.ReactGroupingRule;
import com.pspdfkit.views.PdfView;
import com.pspdfkit.configuration.activity.PdfActivityConfiguration;


import org.json.JSONObject;

import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;
Expand All @@ -65,14 +60,18 @@ public class ReactPdfViewManager extends ViewGroupManager<PdfView> {
public static final int COMMAND_REMOVE_FRAGMENT = 12;
public static final int COMMAND_SET_TOOLBAR_MENU_ITEMS = 13;
public static final int COMMAND_REMOVE_ANNOTATIONS = 14;
public static final int COMMAND_SET_MEASUREMENT_SCALE = 17;
public static final int COMMAND_SET_MEASUREMENT_PRECISION = 16;

private CompositeDisposable annotationDisposables = new CompositeDisposable();
private final CompositeDisposable annotationDisposables = new CompositeDisposable();

@NonNull
@Override
public String getName() {
return "RCTPSPDFKitView";
}

@NonNull
@Override
protected PdfView createViewInstance(ThemedReactContext reactContext) {
Activity currentActivity = reactContext.getCurrentActivity();
Expand Down Expand Up @@ -111,6 +110,8 @@ public Map<String, Integer> getCommandsMap() {
commandMap.put("getAllAnnotations", COMMAND_GET_ALL_ANNOTATIONS);
commandMap.put("removeFragment", COMMAND_REMOVE_FRAGMENT);
commandMap.put("setToolbarMenuItems", COMMAND_SET_TOOLBAR_MENU_ITEMS);
commandMap.put("setMeasurementScale", COMMAND_SET_MEASUREMENT_SCALE);
commandMap.put("setMeasurementPrecision", COMMAND_SET_MEASUREMENT_PRECISION);
return commandMap;
}

Expand Down Expand Up @@ -192,7 +193,7 @@ public Map getExportedCustomDirectEventTypeConstants() {
}

@Override
public void receiveCommand(final PdfView root, int commandId, @Nullable ReadableArray args) {
public void receiveCommand(@NonNull final PdfView root, int commandId, @Nullable ReadableArray args) {
switch (commandId) {
case COMMAND_ENTER_ANNOTATION_CREATION_MODE:
root.enterAnnotationCreationMode();
Expand Down Expand Up @@ -268,12 +269,8 @@ public void accept(List<Annotation> annotations) {
Disposable annotationDisposable = root.getAllUnsavedAnnotations()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<JSONObject>() {
@Override
public void accept(JSONObject jsonObject) {
root.getEventDispatcher().dispatchEvent(new PdfViewDataReturnedEvent(root.getId(), requestId, jsonObject));
}
});
.subscribe(jsonObject -> root.getEventDispatcher()
.dispatchEvent(new PdfViewDataReturnedEvent(root.getId(), requestId, jsonObject)));
annotationDisposables.add(annotationDisposable);
}
break;
Expand Down Expand Up @@ -316,6 +313,28 @@ public void accept(JSONObject jsonObject) {
setToolbarMenuItems(root,args.getArray(0));
}
break;
case COMMAND_SET_MEASUREMENT_SCALE:
if (args != null) {
final int requestId = args.getInt(0);
try {
boolean result = root.setMeasurementScale(args.getMap(1));
root.getEventDispatcher().dispatchEvent(new PdfViewDataReturnedEvent(root.getId(), requestId, result));
} catch (Exception e) {
root.getEventDispatcher().dispatchEvent(new PdfViewDataReturnedEvent(root.getId(), requestId, e));
}
}
break;
case COMMAND_SET_MEASUREMENT_PRECISION:
if (args != null) {
final int requestId = args.getInt(0);
try {
boolean result = root.setMeasurementPrecision(args.getString(1));
root.getEventDispatcher().dispatchEvent(new PdfViewDataReturnedEvent(root.getId(), requestId, result));
} catch (Exception e) {
root.getEventDispatcher().dispatchEvent(new PdfViewDataReturnedEvent(root.getId(), requestId, e));
}
}
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
* This notice may not be removed from this file.
*/

package com.pspdfkit.react;

import com.facebook.react.bridge.ReadableArray;
Expand Down
Loading

0 comments on commit 049ac9d

Please sign in to comment.