Skip to content

Commit 4d5984e

Browse files
authored
Merge pull request #141 from PSPDFKit/reinhard/update-pspdfkit
Update react wrapper to PSPDFKit 5.0
2 parents 7289e06 + f0c04df commit 4d5984e

File tree

12 files changed

+67
-57
lines changed

12 files changed

+67
-57
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ editableAnnotationTypes: ["Ink", "Highlight"];
247247

248248
- Android SDK
249249
- Android Build Tools 23.0.1 (React Native)
250-
- Android Build Tools 26.0.1 (PSPDFKit module)
251-
- PSPDFKit >= 4.6.0
250+
- Android Build Tools 28.0.3 (PSPDFKit module)
251+
- PSPDFKit >= 5.0.1
252252
- react-native >= 0.55.4
253253

254254
#### Getting Started
@@ -287,15 +287,15 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
287287
}
288288
```
289289

290-
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):
290+
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):
291291

292292
```diff
293293
...
294294
android {
295295
- compileSdkVersion 23
296-
+ compileSdkVersion 26
296+
+ compileSdkVersion 28
297297
- buildToolsVersion "23.0.1"
298-
+ buildToolsVersion "26.0.1"
298+
+ buildToolsVersion "28.0.3"
299299

300300
defaultConfig {
301301
applicationId "com.yourapp"
@@ -310,6 +310,11 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
310310
abiFilters "armeabi-v7a", "x86"
311311
}
312312
}
313+
314+
compileOptions {
315+
+ sourceCompatibility JavaVersion.VERSION_1_8
316+
+ targetCompatibility JavaVersion.VERSION_1_8
317+
}
313318
...
314319
```
315320

android/build.gradle

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@
22
* Contains gradle configuration constants
33
*/
44
ext {
5-
PSPDFKIT_VERSION = '4.8.1'
5+
PSPDFKIT_VERSION = '5.0.1'
66
}
77

88
buildscript {
99
repositories {
1010
jcenter()
11+
maven {
12+
url 'https://maven.google.com'
13+
}
1114
}
1215

1316
dependencies {
14-
classpath 'com.android.tools.build:gradle:2.3.1'
17+
classpath 'com.android.tools.build:gradle:3.2.1'
1518
}
1619
}
1720

1821
apply plugin: 'com.android.library'
1922

2023
android {
21-
compileSdkVersion 26
22-
buildToolsVersion "26.0.1"
24+
compileSdkVersion 28
25+
buildToolsVersion "28.0.3"
2326

2427
defaultConfig {
2528
minSdkVersion 19
2629
targetSdkVersion 26
2730
versionCode 1
2831
versionName "1.0"
2932
}
33+
34+
compileOptions {
35+
sourceCompatibility JavaVersion.VERSION_1_8
36+
targetCompatibility JavaVersion.VERSION_1_8
37+
}
38+
3039
lintOptions {
3140
abortOnError false
3241
}

android/src/main/java/com/pspdfkit/react/ReactPdfViewManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void accept(List<Annotation> annotations) {
175175
break;
176176
case COMMAND_ADD_ANNOTATION:
177177
if (args != null) {
178-
root.addAnnotation(args.getMap(0));
178+
annotationDisposables.add(root.addAnnotation(args.getMap(0)));
179179
}
180180
break;
181181
case COMMAND_GET_ALL_UNSAVED_ANNOTATIONS:
@@ -195,7 +195,7 @@ public void accept(JSONObject jsonObject) {
195195
break;
196196
case COMMAND_ADD_ANNOTATIONS:
197197
if (args != null && args.size() == 1) {
198-
root.addAnnotations(args.getMap(0));
198+
annotationDisposables.add(root.addAnnotations(args.getMap(0)));
199199
}
200200
break;
201201
case COMMAND_GET_FORM_FIELD_VALUE:

android/src/main/java/com/pspdfkit/views/PdfView.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.pspdfkit.configuration.activity.PdfActivityConfiguration;
1919
import com.pspdfkit.configuration.activity.ThumbnailBarMode;
2020
import com.pspdfkit.document.PdfDocument;
21+
import com.pspdfkit.document.PdfDocumentLoader;
2122
import com.pspdfkit.document.formatters.DocumentJsonFormatter;
2223
import com.pspdfkit.document.providers.DataProvider;
2324
import com.pspdfkit.forms.ChoiceFormElement;
@@ -91,7 +92,8 @@ public class PdfView extends FrameLayout {
9192
@Nullable
9293
private PdfFragment fragment;
9394
private BehaviorSubject<PdfFragment> fragmentGetter = BehaviorSubject.create();
94-
@Nullable private PdfTextSelectionPopupToolbar textSelectionPopupToolbar;
95+
@Nullable
96+
private PdfTextSelectionPopupToolbar textSelectionPopupToolbar;
9597

9698
public PdfView(@NonNull Context context) {
9799
super(context);
@@ -173,7 +175,7 @@ public void setDocument(String document) {
173175
documentOpeningDisposable.dispose();
174176
}
175177
updateState();
176-
documentOpeningDisposable = PdfDocument.openDocumentAsync(getContext(), Uri.parse(document))
178+
documentOpeningDisposable = PdfDocumentLoader.openDocumentAsync(getContext(), Uri.parse(document))
177179
.subscribeOn(Schedulers.io())
178180
.observeOn(AndroidSchedulers.mainThread())
179181
.subscribe(new Consumer<PdfDocument>() {
@@ -240,7 +242,7 @@ private void prepareFragment(final PdfFragment pdfFragment) {
240242
public void onDocumentLoaded(@NonNull PdfDocument document) {
241243
manuallyLayoutChildren();
242244
pdfFragment.setPageIndex(pageIndex, false);
243-
pdfThumbnailBar.setDocument(document, configuration.getConfiguration(), pdfFragment.getEventBus());
245+
pdfThumbnailBar.setDocument(document, configuration.getConfiguration());
244246
updateState();
245247
}
246248

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

455-
public void addAnnotation(ReadableMap annotation) {
456-
JSONObject json = new JSONObject(annotation.toHashMap());
457-
fragment.getDocument().getAnnotationProvider().createAnnotationFromInstantJson(json.toString());
457+
public Disposable addAnnotation(ReadableMap annotation) {
458+
return fragmentGetter.take(1).map(PdfFragment::getDocument).subscribeOn(Schedulers.io())
459+
.observeOn(AndroidSchedulers.mainThread())
460+
.subscribe(pdfDocument -> {
461+
JSONObject json = new JSONObject(annotation.toHashMap());
462+
pdfDocument.getAnnotationProvider().createAnnotationFromInstantJson(json.toString());
463+
});
464+
458465
}
459466

460467
public Single<JSONObject> getAllUnsavedAnnotations() {
@@ -471,10 +478,14 @@ public JSONObject call() throws Exception {
471478
});
472479
}
473480

474-
public void addAnnotations(ReadableMap annotation) {
475-
JSONObject json = new JSONObject(annotation.toHashMap());
476-
final DataProvider dataProvider = new DocumentJsonDataProvider(json);
477-
DocumentJsonFormatter.importDocumentJson(fragment.getDocument(), dataProvider);
481+
public Disposable addAnnotations(ReadableMap annotation) {
482+
return fragmentGetter.take(1).map(PdfFragment::getDocument).subscribeOn(Schedulers.io())
483+
.observeOn(AndroidSchedulers.mainThread())
484+
.subscribe(pdfDocument -> {
485+
JSONObject json = new JSONObject(annotation.toHashMap());
486+
final DataProvider dataProvider = new DocumentJsonDataProvider(json);
487+
DocumentJsonFormatter.importDocumentJson(pdfDocument, dataProvider);
488+
});
478489
}
479490

480491
public Disposable getFormFieldValue(final int requestId, @NonNull String formElementName) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<attr name="pspdf__redactionIcon" format="reference"/>
4+
</resources>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "1.21.1",
3+
"version": "1.22.0",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

samples/Catalog/android/app/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def enableSeparateBuildPerCPUArchitecture = false
8888
def enableProguardInReleaseBuilds = false
8989

9090
android {
91-
compileSdkVersion 26
92-
buildToolsVersion "26.0.1"
91+
compileSdkVersion 28
92+
buildToolsVersion "28.0.3"
9393

9494
defaultConfig {
9595
applicationId "com.pspdfkit.react.catalog"
@@ -103,6 +103,12 @@ android {
103103
}
104104
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
105105
}
106+
107+
compileOptions {
108+
sourceCompatibility JavaVersion.VERSION_1_8
109+
targetCompatibility JavaVersion.VERSION_1_8
110+
}
111+
106112
splits {
107113
abi {
108114
reset()

samples/Catalog/android/app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
<resources>
1616
<color name="pspdf_color">#3C97C9</color>
1717
<color name="pspdf_color_dark">#306F8B</color>
18+
<color name="color_gray_light">#E0E0E0</color>
1819

1920
</resources>

samples/Catalog/android/app/src/main/res/values/styles.xml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,7 @@
2222
<item name="windowNoTitle">true</item>
2323
<item name="windowActionModeOverlay">true</item>
2424

25-
<item name="alertDialogTheme">@style/pspdf__AlertDialog</item>
26-
<item name="textColorError">@color/pspdf__color_error</item>
27-
28-
<item name="pspdf__backgroundColor">@color/pspdf__color_gray_light</item>
29-
<item name="pspdf__contextualToolbarBackground">@color/pspdf_color_dark</item>
30-
<item name="pspdf__contextualToolbarSubmenuBackground">@color/pspdf_color</item>
31-
<item name="pspdf__actionBarIconsStyle">@style/pspdf__ActionBarIcons</item>
32-
<item name="pspdf__outlineViewStyle">@style/pspdf__OutlineView</item>
33-
<item name="pspdf__inlineSearchStyle">@style/pspdf__SearchViewInline</item>
34-
<item name="pspdf__modularSearchStyle">@style/pspdf__SearchViewModular</item>
35-
<item name="pspdf__thumbnailBarStyle">@style/pspdf__ThumbnailBar</item>
36-
<item name="pspdf__thumbnailGridStyle">@style/pspdf__ThumbnailGrid</item>
37-
<item name="pspdf__searchResultHighlighterStyle">@style/pspdf__SearchResultHighlighter</item>
38-
<item name="pspdf__annotationStyle">@style/pspdf__Annotation</item>
39-
<item name="pspdf__annotationSelectionStyle">@style/pspdf__AnnotationSelection</item>
40-
<item name="pspdf__annotationCreationToolbarIconsStyle">@style/pspdf__AnnotationCreationToolbarIcons</item>
41-
<item name="pspdf__annotationEditingToolbarIconsStyle">@style/pspdf__AnnotationEditingToolbarIcons</item>
42-
<item name="pspdf__textSelectionToolbarIconsStyle">@style/pspdf__TextSelectionToolbarIcons</item>
43-
<item name="pspdf__documentEditingToolbarIconsStyle">@style/pspdf__DocumentEditingToolbarIcons</item>
44-
<item name="pspdf__toolbarCoordinatorLayoutStyle">@style/pspdf__ToolbarCoordinatorLayout</item>
45-
<item name="pspdf__signatureLayoutStyle">@style/pspdf__SignatureLayout</item>
46-
<item name="pspdf__passwordViewStyle">@style/pspdf__PasswordView</item>
47-
<item name="pspdf__propertyInspectorStyle">@style/pspdf__PropertyInspector</item>
48-
<item name="pspdf__actionMenuStyle">@style/pspdf__ActionMenu</item>
49-
<item name="pspdf__sharingDialogStyle">@style/pspdf__SharingDialog</item>
50-
<item name="pspdf__stampPickerStyle">@style/pspdf__StampPicker</item>
51-
<item name="pspdf__newPageDialogStyle">@style/pspdf__NewPageDialog</item>
52-
<item name="pspdf__modalDialogStyle">@style/pspdf__ModalDialog</item>
53-
<item name="pspdf__formSelectionStyle">@style/pspdf__FormSelection</item>
54-
<item name="pspdf__formEditingBarStyle">@style/pspdf__FormEditingBar</item>
25+
<item name="pspdf__backgroundColor">@color/color_gray_light</item>
5526
</style>
5627

5728
<style name="PSPDFCatalog.Theme.Light"/>

0 commit comments

Comments
 (0)