Skip to content

Commit

Permalink
Added transition options: curl, flip, fade, slide
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Feb 15, 2016
1 parent 32526f4 commit 914d38b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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`.
13 changes: 7 additions & 6 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
};
</script>
</head>
<body>
<body style="background: none; background-color: #ddd">
<div class="app">
<h1>Safari VC</h1>

Expand All @@ -34,20 +34,21 @@ <h1>Safari VC</h1>
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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<plugin
id="cordova-plugin-safariviewcontroller"
version="1.2.0"
version="1.3.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0">

<name>SafariViewController</name>
Expand Down
29 changes: 24 additions & 5 deletions src/ios/SafariViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand Down

0 comments on commit 914d38b

Please sign in to comment.