diff --git a/README.md b/README.md
index b7233d0..0f63e98 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,7 @@ function openUrl(url, readerMode) {
SafariViewController.show({
url: url,
animated: false, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
+ transition: 'curl', // unless animated is false you can choose from: curl, flip, fade, slide (default)
enterReaderModeIfAvailable: readerMode // default false
},
// this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
@@ -95,4 +96,5 @@ function dismissSafari() {
* Whereas `cordova-plugin-inappbrowser` is affected by [ATS](https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/), this plugin is not. This means you can even load `http` URL's without whitelisting them.
## 6. Changelog
+1.3.0 `isAvailable` plays nice with non-iOS platforms. Added a `transition` property to `show`.
1.2.0 Added lifecycle events to the success handler of `show`, and added the `animated` property to `show`.
\ No newline at end of file
diff --git a/demo/index.html b/demo/index.html
index a1038a0..88ad410 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -12,7 +12,7 @@
};
-
+
Safari VC
@@ -34,20 +34,21 @@
Safari VC
if (available) {
SafariViewController.show({
url: url,
- animated: false, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
+ animated: true, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
+ transition: 'curl', // unless animated is false you can choose from: curl, flip, fade, slide (default)
enterReaderModeIfAvailable: readerMode // default false
},
function(result) {
if (result.event === 'opened') {
- alert('opened');
+ console.log('opened');
} else if (result.event === 'loaded') {
- alert('loaded');
+ console.log('loaded');
} else if (result.event === 'closed') {
- alert('closed');
+ console.log('closed');
}
},
function(msg) {
- alert("KO: " + msg);
+ console.log("KO: " + JSON.stringify(msg));
})
} else {
// potentially powered by InAppBrowser because that (currently) clobbers window.open
diff --git a/package.json b/package.json
index 33a7d6b..88e4fc1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-safariviewcontroller",
- "version": "1.2.0",
+ "version": "1.3.0",
"description": "Forget InAppBrowser for iOS - this is way better for displaying read-only web content in your PhoneGap app.",
"cordova": {
"id": "cordova-plugin-safariviewcontroller",
diff --git a/plugin.xml b/plugin.xml
index 3003119..3183b2f 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -1,7 +1,7 @@
SafariViewController
diff --git a/src/ios/SafariViewController.m b/src/ios/SafariViewController.m
index a98c00b..f48a631 100644
--- a/src/ios/SafariViewController.m
+++ b/src/ios/SafariViewController.m
@@ -12,9 +12,9 @@ - (void) isAvailable:(CDVInvokedUrlCommand*)command {
}
- (void) show:(CDVInvokedUrlCommand*)command {
- // testing safariviewcontroller --> requires an isAvailable function to check if isAtLeastVersion(9)
NSDictionary* options = [command.arguments objectAtIndex:0];
- NSString* urlString = [options objectForKey:@"url"];
+ NSString* transition = options[@"transition"];
+ NSString* urlString = options[@"url"];
if (urlString == nil) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"url can't be empty"] callbackId:command.callbackId];
return;
@@ -26,14 +26,33 @@ - (void) show:(CDVInvokedUrlCommand*)command {
vc = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
vc.delegate = self;
- // not really necessary to move the callback to the completion handler
- [self.viewController presentViewController:vc animated:self.animated completion:nil];
- // .. so doing it here
+
+ if (self.animated) {
+ vc.modalTransitionStyle = [self getTransitionStyle:transition];
+ [self.viewController showViewController:vc sender:self];
+ } else {
+ [self.viewController presentViewController:vc animated:NO completion:nil];
+ }
+
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"event":@"opened"}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
+- (UIModalTransitionStyle) getTransitionStyle:(NSString*) input {
+ if (input == nil) {
+ return UIModalTransitionStyleCoverVertical;
+ } else if ([input isEqualToString:@"curl"]) {
+ return UIModalTransitionStylePartialCurl;
+ } else if ([input isEqualToString:@"fade"]) {
+ return UIModalTransitionStyleCrossDissolve;
+ } else if ([input isEqualToString:@"flip"]) {
+ return UIModalTransitionStyleFlipHorizontal;
+ } else {
+ return UIModalTransitionStyleCoverVertical;
+ }
+}
+
- (void) hide:(CDVInvokedUrlCommand*)command {
if (vc != nil) {
[vc dismissViewControllerAnimated:self.animated completion:nil];