Skip to content

Commit

Permalink
Merge pull request #141 from PSPDFKit/reinhard/update-pspdfkit
Browse files Browse the repository at this point in the history
Update react wrapper to PSPDFKit 5.0
  • Loading branch information
irgendeinich authored Nov 15, 2018
2 parents 7289e06 + f0c04df commit 4d5984e
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 57 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ editableAnnotationTypes: ["Ink", "Highlight"];

- Android SDK
- Android Build Tools 23.0.1 (React Native)
- Android Build Tools 26.0.1 (PSPDFKit module)
- PSPDFKit >= 4.6.0
- Android Build Tools 28.0.3 (PSPDFKit module)
- PSPDFKit >= 5.0.1
- react-native >= 0.55.4

#### Getting Started
Expand Down Expand Up @@ -287,15 +287,15 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
}
```

8. PSPDFKit targets modern platforms, so you'll have to update `compileSdkVersion` and `targetSdkVersion` to at least API 26 and enable MultiDex. In `YourApp/android/app/build.gradle` (note **five** places to edit):
8. PSPDFKit targets modern platforms, so you'll have to update `compileSdkVersion` to at least API 28 and `targetSdkVersion` to at least API 26 and enable MultiDex. You also need to enable Java 8 support. In `YourApp/android/app/build.gradle` (note **six** places to edit):

```diff
...
android {
- compileSdkVersion 23
+ compileSdkVersion 26
+ compileSdkVersion 28
- buildToolsVersion "23.0.1"
+ buildToolsVersion "26.0.1"
+ buildToolsVersion "28.0.3"

defaultConfig {
applicationId "com.yourapp"
Expand All @@ -310,6 +310,11 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
abiFilters "armeabi-v7a", "x86"
}
}

compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
}
...
```

Expand Down
17 changes: 13 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,40 @@
* Contains gradle configuration constants
*/
ext {
PSPDFKIT_VERSION = '4.8.1'
PSPDFKIT_VERSION = '5.0.1'
}

buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
abortOnError false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void accept(List<Annotation> annotations) {
break;
case COMMAND_ADD_ANNOTATION:
if (args != null) {
root.addAnnotation(args.getMap(0));
annotationDisposables.add(root.addAnnotation(args.getMap(0)));
}
break;
case COMMAND_GET_ALL_UNSAVED_ANNOTATIONS:
Expand All @@ -195,7 +195,7 @@ public void accept(JSONObject jsonObject) {
break;
case COMMAND_ADD_ANNOTATIONS:
if (args != null && args.size() == 1) {
root.addAnnotations(args.getMap(0));
annotationDisposables.add(root.addAnnotations(args.getMap(0)));
}
break;
case COMMAND_GET_FORM_FIELD_VALUE:
Expand Down
31 changes: 21 additions & 10 deletions android/src/main/java/com/pspdfkit/views/PdfView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.pspdfkit.configuration.activity.PdfActivityConfiguration;
import com.pspdfkit.configuration.activity.ThumbnailBarMode;
import com.pspdfkit.document.PdfDocument;
import com.pspdfkit.document.PdfDocumentLoader;
import com.pspdfkit.document.formatters.DocumentJsonFormatter;
import com.pspdfkit.document.providers.DataProvider;
import com.pspdfkit.forms.ChoiceFormElement;
Expand Down Expand Up @@ -91,7 +92,8 @@ public class PdfView extends FrameLayout {
@Nullable
private PdfFragment fragment;
private BehaviorSubject<PdfFragment> fragmentGetter = BehaviorSubject.create();
@Nullable private PdfTextSelectionPopupToolbar textSelectionPopupToolbar;
@Nullable
private PdfTextSelectionPopupToolbar textSelectionPopupToolbar;

public PdfView(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -173,7 +175,7 @@ public void setDocument(String document) {
documentOpeningDisposable.dispose();
}
updateState();
documentOpeningDisposable = PdfDocument.openDocumentAsync(getContext(), Uri.parse(document))
documentOpeningDisposable = PdfDocumentLoader.openDocumentAsync(getContext(), Uri.parse(document))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<PdfDocument>() {
Expand Down Expand Up @@ -240,7 +242,7 @@ private void prepareFragment(final PdfFragment pdfFragment) {
public void onDocumentLoaded(@NonNull PdfDocument document) {
manuallyLayoutChildren();
pdfFragment.setPageIndex(pageIndex, false);
pdfThumbnailBar.setDocument(document, configuration.getConfiguration(), pdfFragment.getEventBus());
pdfThumbnailBar.setDocument(document, configuration.getConfiguration());
updateState();
}

Expand Down Expand Up @@ -452,9 +454,14 @@ private EnumSet<AnnotationType> getTypeFromString(@Nullable String type) {
return EnumSet.noneOf(AnnotationType.class);
}

public void addAnnotation(ReadableMap annotation) {
JSONObject json = new JSONObject(annotation.toHashMap());
fragment.getDocument().getAnnotationProvider().createAnnotationFromInstantJson(json.toString());
public Disposable addAnnotation(ReadableMap annotation) {
return fragmentGetter.take(1).map(PdfFragment::getDocument).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(pdfDocument -> {
JSONObject json = new JSONObject(annotation.toHashMap());
pdfDocument.getAnnotationProvider().createAnnotationFromInstantJson(json.toString());
});

}

public Single<JSONObject> getAllUnsavedAnnotations() {
Expand All @@ -471,10 +478,14 @@ public JSONObject call() throws Exception {
});
}

public void addAnnotations(ReadableMap annotation) {
JSONObject json = new JSONObject(annotation.toHashMap());
final DataProvider dataProvider = new DocumentJsonDataProvider(json);
DocumentJsonFormatter.importDocumentJson(fragment.getDocument(), dataProvider);
public Disposable addAnnotations(ReadableMap annotation) {
return fragmentGetter.take(1).map(PdfFragment::getDocument).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(pdfDocument -> {
JSONObject json = new JSONObject(annotation.toHashMap());
final DataProvider dataProvider = new DocumentJsonDataProvider(json);
DocumentJsonFormatter.importDocumentJson(pdfDocument, dataProvider);
});
}

public Disposable getFormFieldValue(final int requestId, @NonNull String formElementName) {
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="pspdf__redactionIcon" format="reference"/>
</resources>
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.21.1",
"version": "1.22.0",
"description": "A React Native module for the PSPDFKit library.",
"keywords": [
"react native",
Expand Down
10 changes: 8 additions & 2 deletions samples/Catalog/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
applicationId "com.pspdfkit.react.catalog"
Expand All @@ -103,6 +103,12 @@ android {
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

splits {
abi {
reset()
Expand Down
1 change: 1 addition & 0 deletions samples/Catalog/android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<resources>
<color name="pspdf_color">#3C97C9</color>
<color name="pspdf_color_dark">#306F8B</color>
<color name="color_gray_light">#E0E0E0</color>

</resources>
31 changes: 1 addition & 30 deletions samples/Catalog/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,7 @@
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>

<item name="alertDialogTheme">@style/pspdf__AlertDialog</item>
<item name="textColorError">@color/pspdf__color_error</item>

<item name="pspdf__backgroundColor">@color/pspdf__color_gray_light</item>
<item name="pspdf__contextualToolbarBackground">@color/pspdf_color_dark</item>
<item name="pspdf__contextualToolbarSubmenuBackground">@color/pspdf_color</item>
<item name="pspdf__actionBarIconsStyle">@style/pspdf__ActionBarIcons</item>
<item name="pspdf__outlineViewStyle">@style/pspdf__OutlineView</item>
<item name="pspdf__inlineSearchStyle">@style/pspdf__SearchViewInline</item>
<item name="pspdf__modularSearchStyle">@style/pspdf__SearchViewModular</item>
<item name="pspdf__thumbnailBarStyle">@style/pspdf__ThumbnailBar</item>
<item name="pspdf__thumbnailGridStyle">@style/pspdf__ThumbnailGrid</item>
<item name="pspdf__searchResultHighlighterStyle">@style/pspdf__SearchResultHighlighter</item>
<item name="pspdf__annotationStyle">@style/pspdf__Annotation</item>
<item name="pspdf__annotationSelectionStyle">@style/pspdf__AnnotationSelection</item>
<item name="pspdf__annotationCreationToolbarIconsStyle">@style/pspdf__AnnotationCreationToolbarIcons</item>
<item name="pspdf__annotationEditingToolbarIconsStyle">@style/pspdf__AnnotationEditingToolbarIcons</item>
<item name="pspdf__textSelectionToolbarIconsStyle">@style/pspdf__TextSelectionToolbarIcons</item>
<item name="pspdf__documentEditingToolbarIconsStyle">@style/pspdf__DocumentEditingToolbarIcons</item>
<item name="pspdf__toolbarCoordinatorLayoutStyle">@style/pspdf__ToolbarCoordinatorLayout</item>
<item name="pspdf__signatureLayoutStyle">@style/pspdf__SignatureLayout</item>
<item name="pspdf__passwordViewStyle">@style/pspdf__PasswordView</item>
<item name="pspdf__propertyInspectorStyle">@style/pspdf__PropertyInspector</item>
<item name="pspdf__actionMenuStyle">@style/pspdf__ActionMenu</item>
<item name="pspdf__sharingDialogStyle">@style/pspdf__SharingDialog</item>
<item name="pspdf__stampPickerStyle">@style/pspdf__StampPicker</item>
<item name="pspdf__newPageDialogStyle">@style/pspdf__NewPageDialog</item>
<item name="pspdf__modalDialogStyle">@style/pspdf__ModalDialog</item>
<item name="pspdf__formSelectionStyle">@style/pspdf__FormSelection</item>
<item name="pspdf__formEditingBarStyle">@style/pspdf__FormEditingBar</item>
<item name="pspdf__backgroundColor">@color/color_gray_light</item>
</style>

<style name="PSPDFCatalog.Theme.Light"/>
Expand Down
5 changes: 4 additions & 1 deletion samples/Catalog/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 comments on commit 4d5984e

Please sign in to comment.