Skip to content

Commit ad4dec5

Browse files
author
irgendeinich
committed
Make sure that add annotations waits for the PdfFragment to be available
1 parent 936dbe0 commit ad4dec5

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

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: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,14 @@ private EnumSet<AnnotationType> getTypeFromString(@Nullable String type) {
454454
return EnumSet.noneOf(AnnotationType.class);
455455
}
456456

457-
public void addAnnotation(ReadableMap annotation) {
458-
JSONObject json = new JSONObject(annotation.toHashMap());
459-
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+
460465
}
461466

462467
public Single<JSONObject> getAllUnsavedAnnotations() {
@@ -473,10 +478,14 @@ public JSONObject call() throws Exception {
473478
});
474479
}
475480

476-
public void addAnnotations(ReadableMap annotation) {
477-
JSONObject json = new JSONObject(annotation.toHashMap());
478-
final DataProvider dataProvider = new DocumentJsonDataProvider(json);
479-
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+
});
480489
}
481490

482491
public Disposable getFormFieldValue(final int requestId, @NonNull String formElementName) {

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",

0 commit comments

Comments
 (0)