Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orientation problems are fixed and introduced dismiss event #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ There is a special failure condition on Android, if the system doesn't have any
The plugin downloads the document and provides a preview of the document using the Quick Look framework,
including the corresponding actions such as copy, print, etc.

## Events (only iOS)

* documentHandlerOnDismiss - it fires after QuickLook window is closed

## Example usage

handleDocumentWithURL(
Expand All @@ -38,3 +42,11 @@ including the corresponding actions such as copy, print, etc.
},
'http://www.example.com/path/to/document.pdf'
);

document.addEventListener(
'documentHandlerOnDismiss',
function() {
console.log('document handler was closed');
},
false,
);
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.2",
"name": "ch.ti8m.documenthandler",
"cordova_name": "DocumentHandler",
"description": "A phonegap plugin to handle documents (f.e. PDFs) given by URL.",
"license": "Apache 2.0",
"keywords": [
"cordova",
"Documents",
"PDF"
],
"engines": [],
"cordova": {
"id": "ch.ti8m.documenthandler",
"platforms": [
"ios",
"android"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/onderceylan/DocumentHandler.git"
},
"author": "Document Handler",
"bugs": {
"url": "https://github.com/onderceylan/DocumentHandler/issues"
},
"homepage": "https://github.com/onderceylan/DocumentHandler#readme"
}
4 changes: 4 additions & 0 deletions src/ios/DocumentHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#import <Cordova/CDVPlugin.h>
#import <QuickLook/QuickLook.h>


@interface DocumentHandler : CDVPlugin <QLPreviewControllerDelegate, QLPreviewControllerDataSource, QLPreviewItem>

@property (strong, nonatomic) NSURL* fileUrl;
@property (readonly) NSURL* previewItemURL;
+ (NSNumber *)orientation;
+ (void) setOrientation:(NSNumber*)val;


@end
40 changes: 40 additions & 0 deletions src/ios/DocumentHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@

@implementation DocumentHandler

static NSNumber *orientation = nil;

+ (NSNumber*) orientation {
@synchronized(self) { return orientation; }
}
+ (void) setOrientation:(NSNumber*)val {
@synchronized(self) { orientation = val; }
}

- (void)HandleDocumentWithURL:(CDVInvokedUrlCommand*)command;
{

orientation = [NSNumber numberWithInt:[[UIDevice currentDevice] orientation]];
NSLog(@"setting orientation to");
NSLog(@"%@", orientation);

__weak DocumentHandler* weakSelf = self;

dispatch_queue_t asyncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
Expand Down Expand Up @@ -49,6 +63,32 @@ - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) c
return 1;
}

- (void)previewControllerWillDismiss:(QLPreviewController *)controller {
if (orientation.intValue == 3) {
orientation = [NSNumber numberWithInt:4];
} else if (orientation.intValue == 4) {
orientation = [NSNumber numberWithInt:4];
} else if (orientation.intValue == 5) {
orientation = [NSNumber numberWithInt:4];
} else if (orientation.intValue == 6) {
orientation = [NSNumber numberWithInt:3];
} else {
orientation = [NSNumber numberWithInt:3];
}

NSNumber *currentOrientation = [NSNumber numberWithInt:[[UIDevice currentDevice] orientation]];

if (currentOrientation.intValue == 1 || currentOrientation.intValue == 2) {
[[UIDevice currentDevice] setValue:orientation forKey:@"orientation"];
}
}

- (void)previewControllerDidDismiss:(QLPreviewController *)controller {
NSLog(@"handler dismiss");
NSString *pluginReadyJSCallbackCommand = [NSString stringWithFormat:@"cordova.fireDocumentEvent('documentHandlerOnDismiss');"];
[self.commandDelegate evalJs:pluginReadyJSCallbackCommand];
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
return self;
Expand Down