nativescript-bubble-navigation
Version:
Nativescript plugin for Android & iOS that create beautiful navigation tabs
136 lines • 6.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var bubble_navigation_common_1 = require("./bubble-navigation.common");
var text_base_1 = require("tns-core-modules/ui/text-base/text-base");
var image_source_1 = require("tns-core-modules/image-source/image-source");
var utils_1 = require("tns-core-modules/utils/utils");
var application_1 = require("tns-core-modules/application");
var view_1 = require("tns-core-modules/ui/core/view/view");
var BottomBarControllerDelegate = (function (_super) {
__extends(BottomBarControllerDelegate, _super);
function BottomBarControllerDelegate() {
return _super !== null && _super.apply(this, arguments) || this;
}
BottomBarControllerDelegate.initWithOwner = function (owner) {
var delegate = BottomBarControllerDelegate.new();
delegate._owner = owner;
return delegate;
};
BottomBarControllerDelegate.prototype.tabBarControllerDidSelectViewController = function (tabBarController, viewController) {
var owner = this._owner.get();
owner.onTabSelected(tabBarController.selectedIndex);
};
BottomBarControllerDelegate.ObjCProtocols = [UITabBarControllerDelegate];
return BottomBarControllerDelegate;
}(NSObject));
exports.BottomBarControllerDelegate = BottomBarControllerDelegate;
var BubbleNavigation = (function (_super) {
__extends(BubbleNavigation, _super);
function BubbleNavigation() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(BubbleNavigation.prototype, "ios", {
get: function () {
return this.nativeView;
},
enumerable: true,
configurable: true
});
BubbleNavigation.prototype.createNativeView = function () {
this._tabBarController = BubbleTabBarController.new();
var bottomSafeArea = 0;
if (application_1.ios.window.safeAreaInsets) {
bottomSafeArea = application_1.ios.window.safeAreaInsets.bottom;
}
var bottomBarHeight = 50 + bottomSafeArea;
var actualHeight = this.getActualSize().height;
this.height = actualHeight ? actualHeight : bottomBarHeight;
return this._tabBarController.tabBar;
};
BubbleNavigation.prototype.initNativeView = function () {
this.nativeView.owner = this;
_super.prototype.initNativeView.call(this);
this._delegate = this._tabBarController.delegate = BottomBarControllerDelegate.initWithOwner(new WeakRef(this));
};
BubbleNavigation.prototype.disposeNativeView = function () {
this.nativeView.owner = null;
_super.prototype.disposeNativeView.call(this);
};
BubbleNavigation.prototype.setViewControllers = function () {
this._tabBarController.viewControllers = NSArray.arrayWithArray(this._tabs.map(function (tab) { return tab.viewController; }));
};
BubbleNavigation.prototype.createItem = function (value, id) {
var itemViewController = this.createItemViewController(value, id);
value.viewController = itemViewController;
value.setNativeView(itemViewController.tabBarItem);
return value;
};
BubbleNavigation.prototype.createItemViewController = function (tab, id) {
var itemViewController = UIViewController.new();
itemViewController.tabBarItem = CBTabBarItem.new();
tab.index = id;
var icon;
if (utils_1.isFileOrResourcePath(tab.icon)) {
icon = image_source_1.fromFileOrResource(tab.icon).ios;
}
else {
icon = UIImage.imageNamed(tab.icon);
}
var item = CBTabBarItem.alloc().initWithTitleImageTag(tab.title, icon, tab.index);
if (tab.colorActive) {
item.tintColor = new text_base_1.Color(tab.colorActive).ios;
}
if (tab.colorInactive) {
item.tintInactiveColor = new text_base_1.Color(tab.colorInactive).ios;
}
else {
}
itemViewController.tabBarItem = item;
return itemViewController;
};
BubbleNavigation.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
var width = view_1.layout.getMeasureSpecSize(widthMeasureSpec);
var widthMode = view_1.layout.getMeasureSpecMode(widthMeasureSpec);
var height = view_1.layout.getMeasureSpecSize(heightMeasureSpec);
var heightMode = view_1.layout.getMeasureSpecMode(heightMeasureSpec);
var widthAndState = view_1.View.resolveSizeAndState(width, width, widthMode, 0);
var heightAndState = view_1.View.resolveSizeAndState(height, height, heightMode, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
};
BubbleNavigation.prototype.bindTabs = function (tabs) {
var _this = this;
if (tabs) {
this._tabs = tabs.slice();
this._tabs.forEach(function (tab, index) {
_this.createItem(tab, index);
});
this.setViewControllers();
}
};
BubbleNavigation.prototype.selectTabNative = function (index) {
this._tabBarController.selectedIndex = index;
};
BubbleNavigation.prototype[bubble_navigation_common_1.tabsProperty.getDefault] = function () {
return null;
};
BubbleNavigation.prototype[bubble_navigation_common_1.tabsProperty.setNative] = function (value) {
this.bindTabs(value);
};
BubbleNavigation.prototype[bubble_navigation_common_1.tabBackgroundColorProperty.getDefault] = function () {
return null;
};
BubbleNavigation.prototype[bubble_navigation_common_1.tabBackgroundColorProperty.setNative] = function (color) {
this.nativeView.barTintColor = new text_base_1.Color(color).ios;
};
return BubbleNavigation;
}(bubble_navigation_common_1.BubbleNavigationBase));
exports.BubbleNavigation = BubbleNavigation;
var BubbleNavigationItem = (function (_super) {
__extends(BubbleNavigationItem, _super);
function BubbleNavigationItem(title, icon, colorActive, colorInactive) {
return _super.call(this, title, icon, colorActive, colorInactive) || this;
}
return BubbleNavigationItem;
}(bubble_navigation_common_1.BubbleNavigationItemBase));
exports.BubbleNavigationItem = BubbleNavigationItem;
//# sourceMappingURL=bubble-navigation.ios.js.map