Skip to content

Commit 760dced

Browse files
committed
Add a hide method for iOS
Need to be able to dismiss the preview from JS so that if the app is backgrounded while the preview is up.. the app can dismiss the preview to show the passcode entry screen, etc.
1 parent 415e0f2 commit 760dced

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/ios/FileViewerPlugin.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#import <Cordova/CDV.h>
2+
#import "FileViewerPluginViewController.h"
23

34
@interface FileViewerPlugin : CDVPlugin
5+
{
6+
FileViewerPluginViewController* previewViewController;
7+
}
8+
9+
@property (retain, nonatomic) FileViewerPluginViewController* previewViewController;
410

511
- (void)view:(CDVInvokedUrlCommand*)command;
612
- (void)share:(CDVInvokedUrlCommand*)command;

src/ios/FileViewerPlugin.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#import "FileViewerPlugin.h"
2-
#import "FileViewerPluginViewController.h"
32
#import <Cordova/CDV.h>
43

54
@implementation FileViewerPlugin
5+
@synthesize previewViewController;
66

77
- (void)view:(CDVInvokedUrlCommand*)command
88
{
@@ -12,13 +12,18 @@ - (void)view:(CDVInvokedUrlCommand*)command
1212
NSDictionary* arguments = [command.arguments objectAtIndex:0];
1313
NSString* filePath = [arguments objectForKey:@"url"];
1414

15-
FileViewerPluginViewController* viewController = [[FileViewerPluginViewController alloc] init];
16-
pluginSuccess = [viewController viewFile:filePath usingViewController:[super viewController]];
15+
self.previewViewController = [[FileViewerPluginViewController alloc] init];
16+
pluginSuccess = [self.previewViewController viewFile:filePath usingViewController:[super viewController]];
1717

1818
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:pluginSuccess];
1919
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
2020
}
2121

22+
- (void)hide:(CDVInvokedUrlCommand*)command
23+
{
24+
[self.previewViewController.documentInteractionController dismissPreviewAnimated:YES];
25+
}
26+
2227
- (void)share:(CDVInvokedUrlCommand*)command
2328
{
2429
NSDictionary* arguments = [command.arguments objectAtIndex:0];

www/FileViewerPlugin.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
}, 'FileViewerPlugin', 'view', [params]);
2020
};
2121

22+
// Only really useful on iOS
23+
FileViewerPlugin.prototype.hide = function() {
24+
return exec(null, null, 'FileViewerPlugin', 'hide', []);
25+
};
26+
2227
FileViewerPlugin.prototype.share = function(params, success, fail) {
2328
return exec(function(args) {
2429
success(args);

0 commit comments

Comments
 (0)