Merge pull request #693 from AndiDog/master

Port to Cordova 2.0 and backwards compatibility iOS < 5.0
This commit is contained in:
tommy-carlos williams
2012-07-28 03:09:52 -07:00
7 changed files with 40 additions and 43 deletions

View File

@@ -1,11 +1,10 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UINavigationBar.h>
#ifdef CORDOVA_FRAMEWORK
// For older versions of Cordova, you may have to use: #import "CDVPlugin.h"
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif
#import "CDVNavigationBarController.h"
@interface NavigationBar : CDVPlugin <CDVNavigationBarDelegate> {

View File

@@ -10,7 +10,7 @@ function NavigationBar() {
*/
NavigationBar.prototype.create = function(style)
{
Cordova.exec("NavigationBar.create", style || "Default");
cordova.exec("NavigationBar.create", style || "Default");
};
/**
@@ -18,11 +18,11 @@ NavigationBar.prototype.create = function(style)
*/
NavigationBar.prototype.init = function()
{
Cordova.exec("NavigationBar.init");
cordova.exec("NavigationBar.init");
};
NavigationBar.prototype.resize = function() {
Cordova.exec("NavigationBar.resize");
cordova.exec("NavigationBar.resize");
};
/**
@@ -31,17 +31,17 @@ NavigationBar.prototype.resize = function() {
NavigationBar.prototype.setupLeftButton = function(title, image, onselect, options)
{
this.leftButtonCallback = onselect;
Cordova.exec("NavigationBar.setupLeftButton", title || "", image || "", options || {});
cordova.exec("NavigationBar.setupLeftButton", title || "", image || "", options || {});
};
NavigationBar.prototype.hideLeftButton = function()
{
Cordova.exec("NavigationBar.hideLeftButton");
cordova.exec("NavigationBar.hideLeftButton");
};
NavigationBar.prototype.showLeftButton = function()
{
Cordova.exec("NavigationBar.showLeftButton");
cordova.exec("NavigationBar.showLeftButton");
};
/**
@@ -59,18 +59,18 @@ NavigationBar.prototype.leftButtonTapped = function()
NavigationBar.prototype.setupRightButton = function(title, image, onselect, options)
{
this.rightButtonCallback = onselect;
Cordova.exec("NavigationBar.setupRightButton", title || "", image || "", onselect, options || {});
cordova.exec("NavigationBar.setupRightButton", title || "", image || "", onselect, options || {});
};
NavigationBar.prototype.hideRightButton = function()
{
Cordova.exec("NavigationBar.hideRightButton");
cordova.exec("NavigationBar.hideRightButton");
};
NavigationBar.prototype.showRightButton = function()
{
Cordova.exec("NavigationBar.showRightButton");
cordova.exec("NavigationBar.showRightButton");
};
/**
@@ -84,19 +84,19 @@ NavigationBar.prototype.rightButtonTapped = function()
NavigationBar.prototype.setTitle = function(title)
{
Cordova.exec("NavigationBar.setTitle", title);
cordova.exec("NavigationBar.setTitle", title);
};
NavigationBar.prototype.setLogo = function(imageURL)
{
Cordova.exec("NavigationBar.setLogo", imageURL);
cordova.exec("NavigationBar.setLogo", imageURL);
};
/**
* Shows the navigation bar. Make sure you called create() first.
*/
NavigationBar.prototype.show = function() {
Cordova.exec("NavigationBar.show");
cordova.exec("NavigationBar.show");
};
/**
@@ -104,15 +104,14 @@ NavigationBar.prototype.show = function() {
*/
NavigationBar.prototype.hide = function() {
Cordova.exec("NavigationBar.hide");
cordova.exec("NavigationBar.hide");
};
Cordova.addConstructor(function()
cordova.addConstructor(function()
{
if(!window.plugins)
{
window.plugins = {};
}
window.plugins.navigationBar = new NavigationBar();
});

View File

@@ -12,11 +12,8 @@
#import <UIKit/UITabBar.h>
#import <QuartzCore/QuartzCore.h>
#ifdef CORDOVA_FRAMEWORK
// For older versions of Cordova, you may have to use: #import "CDVDebug.h"
#import <Cordova/CDVDebug.h>
#else
#import "CDVDebug.h"
#endif
@implementation NavigationBar
#ifndef __IPHONE_3_0
@@ -55,7 +52,14 @@
-(UIBarButtonItem*)backgroundButtonFromImage:(NSString*)imageName title:(NSString*)title fixedMarginLeft:(float)fixedMarginLeft fixedMarginRight:(float)fixedMarginRight target:(id)target action:(SEL)action
{
UIButton *backButton = [[UIButton alloc] init];
UIImage *imgNormal = [[UIImage imageNamed:imageName] resizableImageWithCapInsets:UIEdgeInsetsMake(0, fixedMarginLeft, 0, fixedMarginRight)];
UIImage *imgNormal = [UIImage imageNamed:imageName];
// UIImage's resizableImageWithCapInsets method is only available from iOS 5.0. With earlier versions, the
// stretchableImageWithLeftCapWidth is used which behaves a bit differently.
if([imgNormal respondsToSelector:@selector(resizableImageWithCapInsets)])
imgNormal = [imgNormal resizableImageWithCapInsets:UIEdgeInsetsMake(0, fixedMarginLeft, 0, fixedMarginRight)];
else
imgNormal = [imgNormal stretchableImageWithLeftCapWidth:MAX(fixedMarginLeft, fixedMarginRight) topCapHeight:0];
[backButton setBackgroundImage:imgNormal forState:UIControlStateNormal];

View File

@@ -91,7 +91,7 @@ There are [several ways](http://stackoverflow.com/questions/227078/creating-a-le
![Screenshot](http://i.imgur.com/naC96.png)
The above screenshot has a navigation bar with two such custom buttons. The left one actually has a background image very similar to the black iOS navigation bar. A stretchable picture (such as [this](http://imgur.com/yibWD) or [that one](http://imgur.com/K2LUS) which were used above) should be used because the plugin automatically sets the button size according to the text size (but not smaller than the original picture). You can define left/right margins which shall not be stretched if the button width changes.
The above screenshot has a navigation bar with two such custom buttons. The left one actually has a background image very similar to the black iOS navigation bar. A stretchable picture (such as [this](http://imgur.com/yibWD) or [that one](http://imgur.com/K2LUS) which were used above) should be used because the plugin automatically sets the button size according to the text size (but not smaller than the original picture). You can define left/right margins which shall not be stretched if the button width changes. Important: iOS 5.0 supports defining two different values for the left/right margins. In earlier iOS versions, the plugins takes the larger value (13 pixels in the example below), so please test if your background image looks fine with older versions (install and use the iPhone 4.3 simulator, for example).
Note: Vertical margins are supported by iOS but not implemented in the plugin tell me if you would like that feature. I think you should keep navigation bar buttons at a fixed height (30px on normal 320x480 iPhone display).

View File

@@ -14,11 +14,9 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UITabBar.h>
#ifdef CORDOVA_FRAMEWORK
// For older versions of Cordova, you may have to use: #import "CDVPlugin.h"
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif
@interface TabBar : CDVPlugin <UITabBarDelegate> {
UITabBar* tabBar;

View File

@@ -17,7 +17,7 @@ function TabBar() {
* Create a native tab bar that can have tab buttons added to it which can respond to events.
*/
TabBar.prototype.create = function() {
Cordova.exec("TabBar.create");
cordova.exec("TabBar.create");
};
/**
@@ -53,7 +53,7 @@ TabBar.prototype.createItem = function(name, label, image, options) {
//delete options.onSelect;
}
Cordova.exec("TabBar.createItem", name, label, image, tag, options);
cordova.exec("TabBar.createItem", name, label, image, tag, options);
};
/**
@@ -71,7 +71,7 @@ TabBar.prototype.getSelectedItem = function() {
TabBar.prototype.hide = function(animate) {
if (animate === undefined || animate === null)
animate = true;
Cordova.exec("TabBar.hide", {animate: animate});
cordova.exec("TabBar.hide", {animate: animate});
};
/**
@@ -79,7 +79,7 @@ TabBar.prototype.hide = function(animate) {
*/
TabBar.prototype.init = function()
{
Cordova.exec("TabBar.init");
cordova.exec("TabBar.init");
};
/**
@@ -94,7 +94,7 @@ TabBar.prototype.onItemSelected = function(tag)
};
TabBar.prototype.resize = function() {
Cordova.exec("TabBar.resize");
cordova.exec("TabBar.resize");
};
/**
@@ -104,7 +104,7 @@ TabBar.prototype.resize = function() {
* @see showItems
*/
TabBar.prototype.selectItem = function(tab) {
Cordova.exec("TabBar.selectItem", tab);
cordova.exec("TabBar.selectItem", tab);
};
/**
@@ -116,7 +116,7 @@ TabBar.prototype.selectItem = function(tab) {
TabBar.prototype.show = function(options) {
if(!options)
options = {position: 'bottom'};
Cordova.exec("TabBar.show", options);
cordova.exec("TabBar.show", options);
};
/**
@@ -132,7 +132,7 @@ TabBar.prototype.showItems = function() {
for (var i = 0; i < arguments.length; i++) {
parameters.push(arguments[i]);
}
Cordova.exec.apply(this, parameters);
cordova.exec.apply(this, parameters);
};
/**
@@ -143,10 +143,10 @@ TabBar.prototype.showItems = function() {
*/
TabBar.prototype.updateItem = function(name, options) {
if (!options) options = {};
Cordova.exec("TabBar.updateItem", name, options);
cordova.exec("TabBar.updateItem", name, options);
};
Cordova.addConstructor(function()
cordova.addConstructor(function()
{
if(!window.plugins)
window.plugins = {};

View File

@@ -17,11 +17,8 @@
#import <UIKit/UINavigationBar.h>
#import <QuartzCore/QuartzCore.h>
#ifdef CORDOVA_FRAMEWORK
// For older versions of Cordova, you may have to use: #import "CDVDebug.h"
#import <Cordova/CDVDebug.h>
#else
#import "CDVDebug.h"
#endif
@implementation TabBar
#ifndef __IPHONE_3_0