nativescript-bottom-navigation
Version:
NativeScript plugin to add a bottom navigation component for Android & iOS
90 lines • 4.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var bottom_navigation_bar_base_1 = require("../base/bottom-navigation-bar.base");
var on_tab_reselected_listener_1 = require("./listeners/on-tab-reselected.listener");
var on_tab_selected_listener_1 = require("./listeners/on-tab-selected.listener");
var utils_1 = require("./utils");
var BottomNavigationView = com.google.android.material.bottomnavigation.BottomNavigationView;
var Menu = android.view.Menu;
var BottomNavigationBar = (function (_super) {
__extends(BottomNavigationBar, _super);
function BottomNavigationBar() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(BottomNavigationBar.prototype, "android", {
get: function () {
return this.nativeView;
},
enumerable: true,
configurable: true
});
BottomNavigationBar.prototype.createNativeView = function () {
var nativeView = new BottomNavigationView(this._context);
var OnTabReselectedListener = on_tab_reselected_listener_1.getOnTabReselectedListener();
nativeView.setOnNavigationItemReselectedListener(new OnTabReselectedListener(this));
var OnTabSelectedListener = on_tab_selected_listener_1.getOnTabSelectedlistener();
nativeView.setOnNavigationItemSelectedListener(new OnTabSelectedListener(this));
return nativeView;
};
BottomNavigationBar.prototype.initNativeView = function () {
_super.prototype.initNativeView.call(this);
this.createTabs(this._items);
this.nativeView.setLabelVisibilityMode(this.titleVisibility);
this.setActiveColor(this.style.activeColor);
this.setInactiveColor(this.style.inactiveColor);
};
BottomNavigationBar.prototype.showBadge = function (index, value) {
var badge = this.nativeView.showBadge(index);
if (value) {
badge.setNumber(value);
}
};
BottomNavigationBar.prototype.removeBadge = function (index) {
this.nativeView.removeBadge(index);
};
BottomNavigationBar.prototype[bottom_navigation_bar_base_1.tabsProperty.setNative] = function (tabs) {
this.createTabs(tabs);
};
BottomNavigationBar.prototype[bottom_navigation_bar_base_1.titleVisibilityProperty.setNative] = function (titleVisibility) {
this.nativeView.setLabelVisibilityMode(titleVisibility);
};
BottomNavigationBar.prototype[bottom_navigation_bar_base_1.activeColorCssProperty.setNative] = function (activeColor) {
this.setActiveColor(activeColor);
};
BottomNavigationBar.prototype[bottom_navigation_bar_base_1.inactiveColorCssProperty.setNative] = function (inactiveColor) {
this.setInactiveColor(inactiveColor);
};
BottomNavigationBar.prototype.createTabs = function (tabs) {
var bottomNavigationTabs = this.nativeView.getMenu();
if (bottomNavigationTabs.size() > 0) {
bottomNavigationTabs.clear();
}
if (tabs) {
this._items = tabs;
}
this._items.forEach(function (tab, index) {
var menuItem = bottomNavigationTabs.add(Menu.NONE, index, Menu.NONE, tab.title);
menuItem.setIcon(tab.getNativeIcon());
});
};
BottomNavigationBar.prototype.selectTabNative = function (index) {
var bottomNavigationTabs = this.nativeView.getMenu();
if (bottomNavigationTabs.size() === 0) {
return;
}
this.nativeView.setSelectedItemId(index);
};
BottomNavigationBar.prototype.setActiveColor = function (activeColor) {
var colorStateList = utils_1.createColorStateList(activeColor, this.style.inactiveColor);
this.nativeView.setItemTextColor(colorStateList);
this.nativeView.setItemIconTintList(colorStateList);
};
BottomNavigationBar.prototype.setInactiveColor = function (inactiveColor) {
var colorStateList = utils_1.createColorStateList(this.style.activeColor, inactiveColor);
this.nativeView.setItemTextColor(colorStateList);
this.nativeView.setItemIconTintList(colorStateList);
};
return BottomNavigationBar;
}(bottom_navigation_bar_base_1.BottomNavigationBarBase));
exports.BottomNavigationBar = BottomNavigationBar;
//# sourceMappingURL=bottom-navigation-bar.js.map