Skip to content

Commit 914d38b

Browse files
Added transition options: curl, flip, fade, slide
1 parent 32526f4 commit 914d38b

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function openUrl(url, readerMode) {
6060
SafariViewController.show({
6161
url: url,
6262
animated: false, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
63+
transition: 'curl', // unless animated is false you can choose from: curl, flip, fade, slide (default)
6364
enterReaderModeIfAvailable: readerMode // default false
6465
},
6566
// this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
@@ -95,4 +96,5 @@ function dismissSafari() {
9596
* 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.
9697

9798
## 6. Changelog
99+
1.3.0 `isAvailable` plays nice with non-iOS platforms. Added a `transition` property to `show`.
98100
1.2.0 Added lifecycle events to the success handler of `show`, and added the `animated` property to `show`.

demo/index.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
};
1313
</script>
1414
</head>
15-
<body>
15+
<body style="background: none; background-color: #ddd">
1616
<div class="app">
1717
<h1>Safari VC</h1>
1818

@@ -34,20 +34,21 @@ <h1>Safari VC</h1>
3434
if (available) {
3535
SafariViewController.show({
3636
url: url,
37-
animated: false, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
37+
animated: true, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
38+
transition: 'curl', // unless animated is false you can choose from: curl, flip, fade, slide (default)
3839
enterReaderModeIfAvailable: readerMode // default false
3940
},
4041
function(result) {
4142
if (result.event === 'opened') {
42-
alert('opened');
43+
console.log('opened');
4344
} else if (result.event === 'loaded') {
44-
alert('loaded');
45+
console.log('loaded');
4546
} else if (result.event === 'closed') {
46-
alert('closed');
47+
console.log('closed');
4748
}
4849
},
4950
function(msg) {
50-
alert("KO: " + msg);
51+
console.log("KO: " + JSON.stringify(msg));
5152
})
5253
} else {
5354
// potentially powered by InAppBrowser because that (currently) clobbers window.open

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-safariviewcontroller",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Forget InAppBrowser for iOS - this is way better for displaying read-only web content in your PhoneGap app.",
55
"cordova": {
66
"id": "cordova-plugin-safariviewcontroller",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0' encoding='UTF-8'?>
22
<plugin
33
id="cordova-plugin-safariviewcontroller"
4-
version="1.2.0"
4+
version="1.3.0"
55
xmlns="http://apache.org/cordova/ns/plugins/1.0">
66

77
<name>SafariViewController</name>

src/ios/SafariViewController.m

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ - (void) isAvailable:(CDVInvokedUrlCommand*)command {
1212
}
1313

1414
- (void) show:(CDVInvokedUrlCommand*)command {
15-
// testing safariviewcontroller --> requires an isAvailable function to check if isAtLeastVersion(9)
1615
NSDictionary* options = [command.arguments objectAtIndex:0];
17-
NSString* urlString = [options objectForKey:@"url"];
16+
NSString* transition = options[@"transition"];
17+
NSString* urlString = options[@"url"];
1818
if (urlString == nil) {
1919
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"url can't be empty"] callbackId:command.callbackId];
2020
return;
@@ -26,14 +26,33 @@ - (void) show:(CDVInvokedUrlCommand*)command {
2626

2727
vc = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
2828
vc.delegate = self;
29-
// not really necessary to move the callback to the completion handler
30-
[self.viewController presentViewController:vc animated:self.animated completion:nil];
31-
// .. so doing it here
29+
30+
if (self.animated) {
31+
vc.modalTransitionStyle = [self getTransitionStyle:transition];
32+
[self.viewController showViewController:vc sender:self];
33+
} else {
34+
[self.viewController presentViewController:vc animated:NO completion:nil];
35+
}
36+
3237
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"event":@"opened"}];
3338
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
3439
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
3540
}
3641

42+
- (UIModalTransitionStyle) getTransitionStyle:(NSString*) input {
43+
if (input == nil) {
44+
return UIModalTransitionStyleCoverVertical;
45+
} else if ([input isEqualToString:@"curl"]) {
46+
return UIModalTransitionStylePartialCurl;
47+
} else if ([input isEqualToString:@"fade"]) {
48+
return UIModalTransitionStyleCrossDissolve;
49+
} else if ([input isEqualToString:@"flip"]) {
50+
return UIModalTransitionStyleFlipHorizontal;
51+
} else {
52+
return UIModalTransitionStyleCoverVertical;
53+
}
54+
}
55+
3756
- (void) hide:(CDVInvokedUrlCommand*)command {
3857
if (vc != nil) {
3958
[vc dismissViewControllerAnimated:self.animated completion:nil];

0 commit comments

Comments
 (0)