nativescript-material-bottomnavigationbar
Version:
NativeScript plugin to add a bottom navigation bar component for Android & iOS
181 lines • 8.61 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BottomNavigationTab = exports.BottomNavigationBar = void 0;
var bottomnavigationbar_common_1 = require("./bottomnavigationbar-common");
var OnTabSelectedlistener;
var getOnTabSelectedlistener = function () {
if (OnTabSelectedlistener) {
return OnTabSelectedlistener;
}
var OnTabSelectedlistenerImpl = (function (_super) {
__extends(OnTabSelectedlistenerImpl, _super);
function OnTabSelectedlistenerImpl(owner) {
var _this = _super.call(this) || this;
_this.owner = owner;
return global.__native(_this);
}
OnTabSelectedlistenerImpl.prototype.onNavigationItemSelected = function (menuItem) {
var index = menuItem.getItemId();
var bottomNavigationTab = this.owner.items[index];
if (bottomNavigationTab.isSelectable) {
this.owner._emitTabSelected(index);
}
else {
this.owner._emitTabPressed(index);
}
return bottomNavigationTab.isSelectable;
};
OnTabSelectedlistenerImpl = __decorate([
Interfaces([com.google.android.material.bottomnavigation.BottomNavigationView.OnNavigationItemSelectedListener]),
__metadata("design:paramtypes", [BottomNavigationBar])
], OnTabSelectedlistenerImpl);
return OnTabSelectedlistenerImpl;
}(java.lang.Object));
OnTabSelectedlistener = OnTabSelectedlistenerImpl;
return OnTabSelectedlistener;
};
var OnTabReselectedListener;
var getOnTabReselectedListener = function () {
if (OnTabReselectedListener) {
return OnTabReselectedListener;
}
var OnTabReselectedListenerImpl = (function (_super) {
__extends(OnTabReselectedListenerImpl, _super);
function OnTabReselectedListenerImpl(owner) {
var _this = _super.call(this) || this;
_this.owner = owner;
return global.__native(_this);
}
OnTabReselectedListenerImpl.prototype.onNavigationItemReselected = function (menuItem) {
this.owner._emitTabReselected(menuItem.getItemId());
};
OnTabReselectedListenerImpl = __decorate([
Interfaces([com.google.android.material.bottomnavigation.BottomNavigationView.OnNavigationItemReselectedListener]),
__metadata("design:paramtypes", [BottomNavigationBar])
], OnTabReselectedListenerImpl);
return OnTabReselectedListenerImpl;
}(java.lang.Object));
OnTabReselectedListener = OnTabReselectedListenerImpl;
return OnTabReselectedListener;
};
function createColorStateList(activeColor, inactiveColor) {
var stateChecked = Array.create('int', 1);
stateChecked[0] = android.R.attr.state_checked;
var stateUnChecked = Array.create('int', 0);
var states = java.lang.reflect.Array.newInstance(stateChecked.getClass() || stateUnChecked.getClass(), 2);
states[0] = stateChecked;
states[1] = stateUnChecked;
var colors = Array.create('int', 2);
colors[0] = activeColor.android;
colors[1] = inactiveColor.android;
return new android.content.res.ColorStateList(states, colors);
}
var BottomNavigationBar = (function (_super) {
__extends(BottomNavigationBar, _super);
function BottomNavigationBar() {
return _super !== null && _super.apply(this, arguments) || this;
}
BottomNavigationBar.prototype.createNativeView = function () {
return new com.google.android.material.bottomnavigation.BottomNavigationView(this._context);
};
BottomNavigationBar.prototype.initNativeView = function () {
_super.prototype.initNativeView.call(this);
var OnTabReselectedListener = getOnTabReselectedListener();
var OnTabSelectedListener = getOnTabSelectedlistener();
this.reselectListener = new OnTabReselectedListener(this);
this.selectListener = new OnTabSelectedListener(this);
this.nativeViewProtected.setOnNavigationItemReselectedListener(this.reselectListener);
this.nativeViewProtected.setOnNavigationItemSelectedListener(this.selectListener);
this.createTabs(this._items);
};
BottomNavigationBar.prototype.disposeNativeView = function () {
var _this = this;
this.nativeViewProtected.setOnNavigationItemReselectedListener(null);
this.nativeViewProtected.setOnNavigationItemSelectedListener(null);
this.reselectListener = null;
this.selectListener = null;
this._items.forEach(function (item) { return _this._removeView(item); });
_super.prototype.disposeNativeView.call(this);
};
BottomNavigationBar.prototype.showBadge = function (index, value) {
var badge = this.nativeViewProtected.getOrCreateBadge(index);
if (value) {
badge.setNumber(value);
}
};
BottomNavigationBar.prototype.removeBadge = function (index) {
this.nativeViewProtected.removeBadge(index);
};
BottomNavigationBar.prototype[bottomnavigationbar_common_1.tabsProperty.setNative] = function (tabs) {
this.createTabs(tabs);
};
BottomNavigationBar.prototype[bottomnavigationbar_common_1.titleVisibilityProperty.setNative] = function (titleVisibility) {
this.nativeViewProtected.setLabelVisibilityMode(titleVisibility);
};
BottomNavigationBar.prototype[bottomnavigationbar_common_1.activeColorCssProperty.setNative] = function (activeColor) {
var colorStateList = createColorStateList(activeColor, this.inactiveColor);
this.nativeViewProtected.setItemTextColor(colorStateList);
this.nativeViewProtected.setItemIconTintList(colorStateList);
};
BottomNavigationBar.prototype[bottomnavigationbar_common_1.inactiveColorCssProperty.setNative] = function (inactiveColor) {
var colorStateList = createColorStateList(this.activeColor, inactiveColor);
this.nativeViewProtected.setItemTextColor(colorStateList);
this.nativeViewProtected.setItemIconTintList(colorStateList);
};
BottomNavigationBar.prototype.createTabs = function (tabs) {
var _this = this;
var bottomNavigationTabs = this.nativeViewProtected.getMenu();
if (bottomNavigationTabs.size() > 0) {
bottomNavigationTabs.clear();
}
if (tabs) {
this._items = tabs;
}
this._items.forEach(function (item, index) {
item.index = index;
_this._addView(item);
var tab = item.nativeViewProtected;
tab.setIcon(item.getNativeIcon());
});
};
BottomNavigationBar.prototype.selectTabNative = function (index) {
var bottomNavigationTabs = this.nativeView.getMenu();
if (bottomNavigationTabs.size() === 0) {
return;
}
this.nativeView.setSelectedItemId(index);
};
return BottomNavigationBar;
}(bottomnavigationbar_common_1.BottomNavigationBarBase));
exports.BottomNavigationBar = BottomNavigationBar;
var BottomNavigationTab = (function (_super) {
__extends(BottomNavigationTab, _super);
function BottomNavigationTab() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.index = android.view.Menu.NONE;
_this._isPaddingRelative = true;
return _this;
}
BottomNavigationTab.prototype.createNativeView = function () {
var view = this.parent.nativeViewProtected.getMenu().add(android.view.Menu.NONE, this.index, android.view.Menu.NONE, this.title);
view.defaultPaddings = { top: 0, left: 0, bottom: 0, right: 0 };
return view;
};
BottomNavigationTab.prototype.initNativeView = function () {
};
BottomNavigationTab.prototype.getNativeIcon = function () {
return this.icon && new android.graphics.drawable.BitmapDrawable(this.icon.android);
};
BottomNavigationTab.prototype.showBadge = function (value) {
this.parent.showBadge(this.index, value);
};
BottomNavigationTab.prototype.removeBadge = function () {
this.parent.removeBadge(this.index);
};
BottomNavigationTab.prototype[bottomnavigationbar_common_1.activeColorCssProperty.setNative] = function (activeColor) {
};
BottomNavigationTab.prototype[bottomnavigationbar_common_1.inactiveColorCssProperty.setNative] = function (inactiveColor) {
};
return BottomNavigationTab;
}(bottomnavigationbar_common_1.BottomNavigationTabBase));
exports.BottomNavigationTab = BottomNavigationTab;
//# sourceMappingURL=bottomnavigationbar.android.js.map