Permalink
Browse files

Animation of show/hide nav buttons, methods for changing title withou…

…t recreating buttons
  • Loading branch information...
1 parent 5f1415d commit 96f352dbb68745c19fe1395bb7f43f53ab1729f4 @AndiDog committed Oct 21, 2012
@@ -13,7 +13,7 @@
// Represents frame of web view as if started in portrait mode. Coordinates are relative to the superview. With
// Cordova 2.1.0, frame.origin.y=0 means directly under the status bar, while in older versions it would have been
// frame.origin.y=20.
- CGRect originalWebViewFrame;
+ CGRect originalWebViewFrame;
CGFloat navBarHeight;
CGFloat tabBarHeight;
@@ -35,8 +35,10 @@
- (void)rightButtonTapped;
- (void)hideLeftButton:(CDVInvokedUrlCommand*)command;
-- (void)showRightButton:(CDVInvokedUrlCommand*)command;
+- (void)setLeftButtonTitle:(CDVInvokedUrlCommand*)command;
+- (void)showLeftButton:(CDVInvokedUrlCommand*)command;
- (void)hideLeftButton:(CDVInvokedUrlCommand*)command;
+- (void)setRightButtonTitle:(CDVInvokedUrlCommand*)command;
- (void)showRightButton:(CDVInvokedUrlCommand*)command;
@end
@@ -38,14 +38,30 @@ NavigationBar.prototype.setupLeftButton = function(title, image, onselect, optio
cordova.exec("NavigationBar.setupLeftButton", title || "", image || "", options || {});
};
-NavigationBar.prototype.hideLeftButton = function()
+/**
+ * @param options: May contain the key "animated" (boolean)
+ */
+NavigationBar.prototype.hideLeftButton = function(options)
+{
+ options = options || {}
+ if(!("animated" in options))
+ options.animated = false
+
+ cordova.exec("NavigationBar.hideLeftButton", options)
+};
+
+NavigationBar.prototype.setLeftButtonTitle = function(title)
{
- cordova.exec("NavigationBar.hideLeftButton");
+ cordova.exec("NavigationBar.setLeftButtonTitle", title)
};
-NavigationBar.prototype.showLeftButton = function()
+NavigationBar.prototype.showLeftButton = function(options)
{
- cordova.exec("NavigationBar.showLeftButton");
+ options = options || {}
+ if(!("animated" in options))
+ options.animated = false
+
+ cordova.exec("NavigationBar.showLeftButton", options)
};
/**
@@ -67,14 +83,27 @@ NavigationBar.prototype.setupRightButton = function(title, image, onselect, opti
};
-NavigationBar.prototype.hideRightButton = function()
+NavigationBar.prototype.hideRightButton = function(options)
+{
+ options = options || {}
+ if(!("animated" in options))
+ options.animated = false
+
+ cordova.exec("NavigationBar.hideRightButton", options)
+};
+
+NavigationBar.prototype.setRightButtonTitle = function(title)
{
- cordova.exec("NavigationBar.hideRightButton");
+ cordova.exec("NavigationBar.setRightButtonTitle", title)
};
-NavigationBar.prototype.showRightButton = function()
+NavigationBar.prototype.showRightButton = function(options)
{
- cordova.exec("NavigationBar.showRightButton");
+ options = options || {}
+ if(!("animated" in options))
+ options.animated = false
+
+ cordova.exec("NavigationBar.showRightButton", options)
};
/**
@@ -113,9 +142,7 @@ NavigationBar.prototype.hide = function() {
cordova.addConstructor(function()
{
- if(!window.plugins)
- {
- window.plugins = {};
- }
- window.plugins.navigationBar = new NavigationBar();
+ if(!window.plugins)
+ window.plugins = {}
+ window.plugins.navigationBar = new NavigationBar()
});
@@ -364,22 +364,48 @@ - (void)setupRightButton:(CDVInvokedUrlCommand*)command
- (void)hideLeftButton:(CDVInvokedUrlCommand*)command
{
- [[navBarController navItem] setLeftBarButtonItem:nil];
+ const NSDictionary *options = [command.arguments objectAtIndex:0];
+ bool animated = [[options objectForKey:@"animated"] boolValue];
+
+ [[navBarController navItem] setLeftBarButtonItem:nil animated:animated];
+}
+
+- (void)setLeftButtonTitle:(CDVInvokedUrlCommand*)command
+{
+ NSString *title = [command.arguments objectAtIndex:0];
+ if(navBarController.navItem.leftBarButtonItem)
+ navBarController.navItem.leftBarButtonItem.title = title;
}
- (void)showLeftButton:(CDVInvokedUrlCommand*)command
{
- [[navBarController navItem] setLeftBarButtonItem:[navBarController leftButton]];
+ const NSDictionary *options = [command.arguments objectAtIndex:0];
+ bool animated = [[options objectForKey:@"animated"] boolValue];
+
+ [[navBarController navItem] setLeftBarButtonItem:[navBarController leftButton] animated:animated];
}
- (void)hideRightButton:(CDVInvokedUrlCommand*)command
{
- [[navBarController navItem] setRightBarButtonItem:nil];
+ const NSDictionary *options = [command.arguments objectAtIndex:0];
+ bool animated = [[options objectForKey:@"animated"] boolValue];
+
+ [[navBarController navItem] setRightBarButtonItem:nil animated:animated];
+}
+
+- (void)setRightButtonTitle:(CDVInvokedUrlCommand*)command
+{
+ NSString *title = [command.arguments objectAtIndex:0];
+ if(navBarController.navItem.rightBarButtonItem)
+ navBarController.navItem.rightBarButtonItem.title = title;
}
- (void)showRightButton:(CDVInvokedUrlCommand*)command
{
- [[navBarController navItem] setRightBarButtonItem:[navBarController rightButton]];
+ const NSDictionary *options = [command.arguments objectAtIndex:0];
+ bool animated = [[options objectForKey:@"animated"] boolValue];
+
+ [[navBarController navItem] setRightBarButtonItem:[navBarController rightButton] animated:animated];
}
-(void) leftButtonTapped

0 comments on commit 96f352d

Please sign in to comment.