Skip to content

Commit 88595ab

Browse files
committed
Flip, curl and fade with callback and options
1 parent e6f294c commit 88595ab

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

src/ios/NativeTransitions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
@interface NativeTransitions : CDVPlugin
1010

11-
- (void) right:(CDVInvokedUrlCommand*)command;
12-
- (void) left:(CDVInvokedUrlCommand*)command;
11+
- (void) flip:(CDVInvokedUrlCommand*)command;
12+
- (void) curl:(CDVInvokedUrlCommand*)command;
1313
- (void) fade:(CDVInvokedUrlCommand*)command;
1414

1515
@end

src/ios/NativeTransitions.m

+32-7
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,52 @@
99

1010
@implementation NativeTransitions
1111

12-
- (void) right:(CDVInvokedUrlCommand*)command;
12+
- (void) flip:(CDVInvokedUrlCommand*)command;
1313
{
1414
NSMutableDictionary *args = [command.arguments objectAtIndex:0];
1515
double duration = [[args objectForKey:@"duration"] doubleValue];
16+
NSString *direction = [[args objectForKey:@"direction"] stringValue];
17+
18+
NSUInteger animation = UIViewAnimationOptionTransitionFlipFromLeft;
19+
20+
if ([direction isEqualToString:@"right"])
21+
{
22+
animation = UIViewAnimationOptionTransitionFlipFromRight;
23+
}
1624

1725
[UIView transitionWithView:self.viewController.view
1826
duration:duration
1927
options:UIViewAnimationOptionAllowAnimatedContent
20-
|UIViewAnimationOptionTransitionFlipFromLeft
28+
|animation
2129
animations:^{}
22-
completion:^(BOOL finished) {}];
30+
completion:^(BOOL finished) {
31+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
32+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
33+
}];
2334
}
2435

25-
- (void) left:(CDVInvokedUrlCommand*)command;
36+
- (void) curl:(CDVInvokedUrlCommand*)command;
2637
{
2738
NSMutableDictionary *args = [command.arguments objectAtIndex:0];
2839
double duration = [[args objectForKey:@"duration"] doubleValue];
40+
NSString *direction = [[args objectForKey:@"direction"] stringValue];
41+
42+
NSUInteger animation = UIViewAnimationOptionTransitionCurlUp;
43+
44+
if ([direction isEqualToString:@"down"])
45+
{
46+
animation = UIViewAnimationOptionTransitionCurlDown;
47+
}
2948

3049
[UIView transitionWithView:self.viewController.view
3150
duration:duration
3251
options:UIViewAnimationOptionAllowAnimatedContent
33-
|UIViewAnimationOptionTransitionFlipFromRight
52+
|animation
3453
animations:^{}
35-
completion:^(BOOL finished) {}];
54+
completion:^(BOOL finished) {
55+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
56+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
57+
}];
3658
}
3759

3860
- (void) fade:(CDVInvokedUrlCommand*)command;
@@ -45,7 +67,10 @@ - (void) fade:(CDVInvokedUrlCommand*)command;
4567
options:UIViewAnimationOptionAllowAnimatedContent
4668
|UIViewAnimationOptionTransitionCrossDissolve
4769
animations:^{}
48-
completion:^(BOOL finished) {}];
70+
completion:^(BOOL finished) {
71+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
72+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
73+
}];
4974
}
5075

5176
@end

www/nativetransitions.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@ var NativeTransitions = function () {
55
this.name = "NativeTransitions";
66
};
77

8-
NativeTransitions.prototype.right = function (success, failure, duration) {
9-
exec(success, failure, "NativeTransitions", "right", [{"duration": duration}]);
8+
NativeTransitions.prototype.flip = function (duration, direction, onComplete) {
9+
var options = {
10+
"duration": duration,
11+
"direction": direction
12+
};
13+
exec(onComplete, null, "NativeTransitions", "flip", [options]);
1014
};
1115

12-
NativeTransitions.prototype.left = function (success, failure, duration) {
13-
exec(success, failure, "NativeTransitions", "left", [{"duration": duration}]);
16+
NativeTransitions.prototype.curl = function (duration, direction, onComplete) {
17+
var options = {
18+
"duration": duration,
19+
"direction": direction
20+
};
21+
exec(onComplete, null, "NativeTransitions", "curl", [options]);
1422
};
1523

16-
NativeTransitions.prototype.fade = function (success, failure, duration) {
17-
exec(success, failure, "NativeTransitions", "fade", [{"duration": duration}]);
24+
NativeTransitions.prototype.fade = function (duration, onComplete) {
25+
var options = {
26+
"duration": duration
27+
};
28+
exec(onComplete, null, "NativeTransitions", "fade", [options]);
1829
};
1930

2031
module.exports = new NativeTransitions();

0 commit comments

Comments
 (0)