Skip to content

Commit

Permalink
Merge pull request #1 from appfeel/master
Browse files Browse the repository at this point in the history
Some improvements
  • Loading branch information
etabard committed Jun 25, 2015
2 parents 7b14854 + 8c2edde commit 8be3840
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/ios/OverAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


- (void)open:(CDVInvokedUrlCommand *)command;
- (void)fade:(CDVInvokedUrlCommand *)command;
- (void)resize:(CDVInvokedUrlCommand *)command;
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand *)command;

Expand Down
63 changes: 57 additions & 6 deletions src/ios/OverAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void) open:(CDVInvokedUrlCommand *)command
}

if (self.overWebView != NULL) {
return;//already created, don't need to create it again
[self browserExit]; // reload it as parameters may have changed
}

CGFloat originx,originy,width;
Expand All @@ -53,6 +53,9 @@ - (void) open:(CDVInvokedUrlCommand *)command
if (argc > 3) {
height = [[arguments objectAtIndex:4] floatValue];
}
if (argc > 4) {
isAutoFadeIn = [[arguments objectAtIndex:5] boolValue];
}

CGRect viewRect = CGRectMake(
originx,
Expand Down Expand Up @@ -85,6 +88,56 @@ - (void) open:(CDVInvokedUrlCommand *)command

}

- (void)fade:(CDVInvokedUrlCommand *)command {
NSArray* arguments = [command arguments];
NSUInteger argc = [arguments count];

if (argc < 2) {
return;
}
[self fadeToAlpha:[[arguments objectAtIndex:0] floatValue] duration:[[arguments objectAtIndex:1] floatValue]];
}

- (void)fadeToAlpha:(float)alpha duration:(float)duration {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: duration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[self.overWebView setAlpha: alpha];
[UIView commitAnimations];
}

- (void)resize:(CDVInvokedUrlCommand *)command {
NSArray* arguments = [command arguments];

NSUInteger argc = [arguments count];

if (argc < 3) { // at a minimum we need x origin, y origin and width...
return;
}

if (self.overWebView == NULL) {
return; // not yet created
}

CGFloat originx,originy,width;
CGFloat height = 30;
originx = [[arguments objectAtIndex:0] floatValue];
originy = [[arguments objectAtIndex:1] floatValue];
width = [[arguments objectAtIndex:2] floatValue];
if (argc > 3) {
height = [[arguments objectAtIndex:3] floatValue];
}

CGRect viewRect = CGRectMake(
originx,
originy,
width,
height
);

self.overWebView.frame = viewRect;
}

- (BOOL)isValidCallbackId:(NSString *)callbackId
{
NSError *err = nil;
Expand Down Expand Up @@ -174,11 +227,9 @@ - (void)webViewDidFinishLoad:(UIWebView*)theWebView
return;
}
if (self.callbackId != nil && self.currentUrl != nil) {
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:1.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
self.overWebView.alpha = 1; /* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above
if (isAutoFadeIn) {
[self fadeToAlpha:1 duration:1.0];
}

// TODO: It would be more useful to return the URL the page is actually on (e.g. if it's been redirected).
NSString* url = [self.currentUrl absoluteString];
Expand Down
14 changes: 10 additions & 4 deletions www/OverAppBrowser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
// OverAppBrowser.js
// OverAppBrowser Cordova Plugin
//
Expand Down Expand Up @@ -32,7 +31,13 @@ OverAppBrowser.prototype = {
exec(null, null, "OverAppBrowser", "close", []);
},
show: function (eventname) {
exec(null, null, "OverAppBrowser", "show", []);
exec(null, null, "OverAppBrowser", "show", []);
},
fade: function (toAlpha, duration) {
exec(null, null, "OverAppBrowser", "fade", [toAlpha, duration]);
},
resize: function (originx, originy, width, height) {
exec(null, null, "OverAppBrowser", "resize", [originx, originy, width, height]);
},
addEventListener: function (eventname,f) {
if (eventname in this.channels) {
Expand Down Expand Up @@ -66,13 +71,14 @@ OverAppBrowser.prototype = {
}
};

module.exports = function(strUrl, originx,originy,width,height) {
module.exports = function(strUrl, originx,originy,width,height, isAutoFadeIn) {
isAutoFadeIn = isAutoFadeIn || false;
strUrl = urlutil.makeAbsolute(strUrl);
var oab = new OverAppBrowser();
var cb = function(eventname) {
oab._eventHandler(eventname);
};

exec(cb, cb, "OverAppBrowser", "open", [strUrl, originx, originy, width, height]);
exec(cb, cb, "OverAppBrowser", "open", [strUrl, originx, originy, width, height, isAutoFadeIn]);
return oab;
};

0 comments on commit 8be3840

Please sign in to comment.