Skip to content

Commit 411f4f2

Browse files
author
RadAzzouz
committed
Add return values for remaining methods
enterAnnotationCreationMode, exitCurrentlyActiveMode, and saveCurrentDocument
1 parent 817629a commit 411f4f2

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class PSPDFKitView extends React.Component {
9797
[]
9898
);
9999
} else if (Platform.OS === "ios") {
100-
NativeModules.PSPDFKitViewManager.enterAnnotationCreationMode(
100+
return NativeModules.PSPDFKitViewManager.enterAnnotationCreationMode(
101101
findNodeHandle(this.refs.pdfView)
102102
);
103103
}
@@ -114,7 +114,7 @@ class PSPDFKitView extends React.Component {
114114
[]
115115
);
116116
} else if (Platform.OS === "ios") {
117-
NativeModules.PSPDFKitViewManager.exitCurrentlyActiveMode(
117+
return NativeModules.PSPDFKitViewManager.exitCurrentlyActiveMode(
118118
findNodeHandle(this.refs.pdfView)
119119
);
120120
}
@@ -131,7 +131,7 @@ class PSPDFKitView extends React.Component {
131131
[]
132132
);
133133
} else if (Platform.OS === "ios") {
134-
NativeModules.PSPDFKitViewManager.saveCurrentDocument(
134+
return NativeModules.PSPDFKitViewManager.saveCurrentDocument(
135135
findNodeHandle(this.refs.pdfView)
136136
);
137137
}

ios/RCTPSPDFKit/RCTPSPDFKitView.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
@property (nonatomic, copy) RCTBubblingEventBlock onStateChanged;
3030

3131
/// Annotation Toolbar
32-
- (void)enterAnnotationCreationMode;
33-
- (void)exitCurrentlyActiveMode;
32+
- (BOOL)enterAnnotationCreationMode;
33+
- (BOOL)exitCurrentlyActiveMode;
3434

3535
/// Document
36-
- (void)saveCurrentDocument;
36+
- (BOOL)saveCurrentDocument;
3737

3838
/// Anotations
3939
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type;

ios/RCTPSPDFKit/RCTPSPDFKitView.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ - (UIViewController *)pspdf_parentViewController {
105105
return nil;
106106
}
107107

108-
- (void)enterAnnotationCreationMode {
108+
- (BOOL)enterAnnotationCreationMode {
109109
[self.pdfController setViewMode:PSPDFViewModeDocument animated:YES];
110110
[self.pdfController.annotationToolbarController updateHostView:nil container:nil viewController:self.pdfController];
111-
[self.pdfController.annotationToolbarController showToolbarAnimated:YES];
111+
return [self.pdfController.annotationToolbarController showToolbarAnimated:YES];
112112
}
113113

114-
- (void)exitCurrentlyActiveMode {
115-
[self.pdfController.annotationToolbarController hideToolbarAnimated:YES];
114+
- (BOOL)exitCurrentlyActiveMode {
115+
return [self.pdfController.annotationToolbarController hideToolbarAnimated:YES];
116116
}
117117

118-
- (void)saveCurrentDocument {
119-
[self.pdfController.document saveWithOptions:nil error:NULL];
118+
- (BOOL)saveCurrentDocument {
119+
return [self.pdfController.document saveWithOptions:nil error:NULL];
120120
}
121121

122122
#pragma mark - PSPDFDocumentDelegate
@@ -249,7 +249,7 @@ - (BOOL)addAnnotations:(id)jsonAnnotations {
249249
if ([jsonAnnotations isKindOfClass:NSString.class]) {
250250
data = [jsonAnnotations dataUsingEncoding:NSUTF8StringEncoding];
251251
} else if ([jsonAnnotations isKindOfClass:NSDictionary.class]) {
252-
data = [NSJSONSerialization dataWithJSONObject:jsonAnnotations options:0 error:nil];;
252+
data = [NSJSONSerialization dataWithJSONObject:jsonAnnotations options:0 error:nil];
253253
} else {
254254
NSLog(@"Invalid JSON Annotations.");
255255
return NO;

ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,39 @@ @implementation RCTPSPDFKitViewManager
7676

7777
RCT_EXPORT_VIEW_PROPERTY(onStateChanged, RCTBubblingEventBlock)
7878

79-
RCT_EXPORT_METHOD(enterAnnotationCreationMode:(nonnull NSNumber *)reactTag) {
79+
RCT_EXPORT_METHOD(enterAnnotationCreationMode:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
8080
dispatch_async(dispatch_get_main_queue(), ^{
8181
RCTPSPDFKitView *component = (RCTPSPDFKitView *)[self.bridge.uiManager viewForReactTag:reactTag];
82-
[component enterAnnotationCreationMode];
82+
BOOL success = [component enterAnnotationCreationMode];
83+
if (success) {
84+
resolve(@(success));
85+
} else {
86+
reject(@"error", @"Failed to enter annotation creation mode.", nil);
87+
}
8388
});
8489
}
8590

86-
RCT_EXPORT_METHOD(exitCurrentlyActiveMode:(nonnull NSNumber *)reactTag) {
91+
RCT_EXPORT_METHOD(exitCurrentlyActiveMode:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
8792
dispatch_async(dispatch_get_main_queue(), ^{
8893
RCTPSPDFKitView *component = (RCTPSPDFKitView *)[self.bridge.uiManager viewForReactTag:reactTag];
89-
[component exitCurrentlyActiveMode];
94+
BOOL success = [component exitCurrentlyActiveMode];
95+
if (success) {
96+
resolve(@(success));
97+
} else {
98+
reject(@"error", @"Failed to exit annotation creation mode.", nil);
99+
}
90100
});
91101
}
92102

93-
RCT_EXPORT_METHOD(saveCurrentDocument:(nonnull NSNumber *)reactTag) {
103+
RCT_EXPORT_METHOD(saveCurrentDocument:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
94104
dispatch_async(dispatch_get_main_queue(), ^{
95105
RCTPSPDFKitView *component = (RCTPSPDFKitView *)[self.bridge.uiManager viewForReactTag:reactTag];
96-
[component saveCurrentDocument];
106+
BOOL success = [component saveCurrentDocument];
107+
if (success) {
108+
resolve(@(success));
109+
} else {
110+
reject(@"error", @"Failed to save document.", nil);
111+
}
97112
});
98113
}
99114

0 commit comments

Comments
 (0)