UNPKG

nativescript-material-bottomnavigationbar

Version:

NativeScript plugin to add a bottom navigation bar component for Android & iOS

148 lines 6.88 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.BottomNavigationTab = exports.BottomNavigationBar = void 0; var application_1 = require("@nativescript/core/application"); var platform_1 = require("@nativescript/core/platform"); var view_1 = require("@nativescript/core/ui/core/view"); var core_1 = require("nativescript-material-core/core"); var bottomnavigationbar_common_1 = require("./bottomnavigationbar-common"); var BottomNavigationBarDelegate = NSObject.extend({ bottomNavigationBarDidSelectItem: function (navigationBar, item) { var owner = this._owner.get(); if (!owner) { return; } if (owner.selectedTabIndex === item.tag) { owner._emitTabReselected(item.tag); return; } owner._emitTabSelected(item.tag); }, bottomNavigationBarShouldSelectItem: function (bottomNavigationBar, item) { var owner = this._owner.get(); if (!owner) { return true; } var bottomNavigationTab = owner.items[item.tag]; if (!bottomNavigationTab.isSelectable) { owner._emitTabPressed(item.tag); } return bottomNavigationTab.isSelectable; }, }, { protocols: [MDCBottomNavigationBarDelegate], }); var BottomNavigationBar = (function (_super) { __extends(BottomNavigationBar, _super); function BottomNavigationBar() { return _super.call(this) || this; } BottomNavigationBar.prototype.createNativeView = function () { var view = MDCBottomNavigationBar.new(); var colorScheme = core_1.themer.getAppColorScheme(); if (colorScheme) { MDCBottomNavigationBarColorThemer.applyColorSchemeToBottomNavigationBar(colorScheme, view); } return view; }; BottomNavigationBar.prototype.initNativeView = function () { _super.prototype.initNativeView.call(this); this._delegate = BottomNavigationBarDelegate.new(); this._delegate._owner = new WeakRef(this); this.nativeViewProtected.delegate = this._delegate; this.createTabs(this._items); }; BottomNavigationBar.prototype.disposeNativeView = function () { var _this = this; this.nativeViewProtected.delegate = null; this._delegate = null; this._items.forEach(function (item) { return _this._removeView(item); }); _super.prototype.disposeNativeView.call(this); }; BottomNavigationBar.prototype.layoutNativeView = function (left, top, right, bottom) { if (!this.nativeViewProtected) { return; } var bottomSafeArea = 0; if (application_1.ios.window.safeAreaInsets) { bottomSafeArea = application_1.ios.window.safeAreaInsets.bottom; } var viewSize = CGSizeMake(platform_1.screen.mainScreen.widthDIPs, platform_1.screen.mainScreen.heightDIPs); var nativeViewSize = this.nativeViewProtected.sizeThatFits(viewSize); var bottomBarHeight = nativeViewSize.height + bottomSafeArea; var nativeView = this.nativeViewProtected; var frame = CGRectMake(0, view_1.layout.toDeviceIndependentPixels(top), viewSize.width, bottomBarHeight); this._setNativeViewFrame(nativeView, frame); }; BottomNavigationBar.prototype.showBadge = function (index, value) { this._items[index] && this._items[index].showBadge(value); }; BottomNavigationBar.prototype.removeBadge = function (index) { this._items[index] && this._items[index].removeBadge(); }; BottomNavigationBar.prototype[bottomnavigationbar_common_1.tabsProperty.setNative] = function (tabs) { this.createTabs(tabs); }; BottomNavigationBar.prototype[bottomnavigationbar_common_1.titleVisibilityProperty.setNative] = function (titleVisibility) { this.nativeViewProtected.titleVisibility = titleVisibility; }; BottomNavigationBar.prototype[bottomnavigationbar_common_1.activeColorCssProperty.setNative] = function (activeColor) { this.nativeViewProtected.selectedItemTintColor = activeColor ? activeColor.ios : null; }; BottomNavigationBar.prototype[bottomnavigationbar_common_1.inactiveColorCssProperty.setNative] = function (inactiveColor) { this.nativeViewProtected.unselectedItemTintColor = inactiveColor ? inactiveColor.ios : null; }; BottomNavigationBar.prototype[view_1.backgroundColorProperty.setNative] = function (backgroundColor) { this.nativeViewProtected.barTintColor = backgroundColor.ios; }; BottomNavigationBar.prototype.createTabs = function (tabs) { var _this = this; if (tabs) { this._items = tabs; } var bottomNavigationTabs = this._items.map(function (item, index) { _this._addView(item); var tab = item.nativeViewProtected; tab.tag = index; return tab; }); this.nativeViewProtected.items = new NSArray({ array: bottomNavigationTabs }); this.selectTabNative(this.selectedTabIndex); }; BottomNavigationBar.prototype.selectTabNative = function (index) { if (this.nativeViewProtected.items.count === 0) { return; } this.nativeViewProtected.selectedItem = this.nativeViewProtected.items[index]; this.selectedTabIndex = index; }; return BottomNavigationBar; }(bottomnavigationbar_common_1.BottomNavigationBarBase)); exports.BottomNavigationBar = BottomNavigationBar; var BottomNavigationTab = (function (_super) { __extends(BottomNavigationTab, _super); function BottomNavigationTab() { return _super !== null && _super.apply(this, arguments) || this; } BottomNavigationTab.prototype.createNativeView = function () { return UITabBarItem.alloc().initWithTitleImageTag(this.title, this.getNativeIcon(), 0); }; BottomNavigationTab.prototype.getNativeIcon = function () { return this.icon && this.icon.ios; }; BottomNavigationTab.prototype.getMDView = function () { return this.parent.nativeViewProtected.viewForItem(this.nativeViewProtected); }; BottomNavigationTab.prototype[bottomnavigationbar_common_1.activeColorCssProperty.setNative] = function (activeColor) { }; BottomNavigationTab.prototype[bottomnavigationbar_common_1.inactiveColorCssProperty.setNative] = function (inactiveColor) { }; BottomNavigationTab.prototype.showBadge = function (value) { this.nativeViewProtected.badgeValue = value ? "" + value : ''; }; BottomNavigationTab.prototype.removeBadge = function () { this.nativeViewProtected.badgeValue = null; }; return BottomNavigationTab; }(bottomnavigationbar_common_1.BottomNavigationTabBase)); exports.BottomNavigationTab = BottomNavigationTab; //# sourceMappingURL=bottomnavigationbar.ios.js.map