UNPKG

@nativescript-community/ui-material-tabs

Version:

Material Design Tabs organize content across different screens, data sets, and other interactions.

120 lines 4.63 kB
import { TabContentItem } from '@nativescript-community/ui-material-core-tabs/tab-content-item'; import { PRIMARY_COLOR, TabNavigation, getDefaultAccentColor } from '@nativescript-community/ui-material-core-tabs/tab-navigation/index.android'; import { TabStrip } from '@nativescript-community/ui-material-core-tabs/tab-strip'; import { TabStripItem } from '@nativescript-community/ui-material-core-tabs/tab-strip-item'; import { CSSType, Utils } from '@nativescript/core'; export { TabContentItem, TabStrip, TabStripItem }; // eslint-disable-next-line no-redeclare let TabsBar; function initializeNativeClasses() { if (TabsBar) { return; } var TabsBarImplementation = /** @class */ (function (_super) { __extends(TabsBarImplementation, _super); function TabsBarImplementation(context, owner) { var _this = _super.call(this, context) || this; _this.owner = owner; return global.__native(_this); } TabsBarImplementation.prototype.onSelectedPositionChange = function (position, prevPosition) { var owner = this.owner; if (!owner) { return; } owner.onTabsBarSelectedPositionChange(position, prevPosition); }; TabsBarImplementation.prototype.onTap = function (position) { var owner = this.owner; if (!owner) { return false; } return owner.onTabsBarTap(position); }; return TabsBarImplementation; }(com.nativescript.material.core.TabsBar)); TabsBar = TabsBarImplementation; } let Tabs = class Tabs extends TabNavigation { createNativeView() { const view = super.createNativeView(); if (this.mTabsBar) { this.mTabsBar.setViewPager(this.mViewPager); } return view; } updateTabsBarItemAt(position, itemSpec) { this.mTabsBar.updateItemAt(position, itemSpec); } setTabsBarSelectedIndicatorColors(colors) { this.mTabsBar.setSelectedIndicatorColors(colors); } getTabBarItemView(index) { return this.mTabsBar.getViewForItemAt(index); } getTabBarItemTextView(index) { return this.mTabsBar.getTextViewForItemAt(index); } createNativeTabBar(context) { initializeNativeClasses(); const tabsBar = new TabsBar(context, this); tabsBar.setViewPager(this.mViewPager); const primaryColor = Utils.android.resources.getPaletteColor(PRIMARY_COLOR, context); const accentColor = getDefaultAccentColor(context); if (accentColor) { tabsBar.setSelectedIndicatorColors([accentColor]); } if (primaryColor) { tabsBar.setBackgroundColor(primaryColor); } tabsBar.setSelectedPosition(this.selectedIndex); return tabsBar; } setTabBarItems(tabItems) { this.mTabsBar.setItems(tabItems); // The setTimeout below is necessary to ensure the scrollToTab is executed only after // all tabs are recreated. The tabs' recreation is triggered by the setItems call above. // // The setTimeout is necessary to fix an Android issue: // Android Issue: Active Tab item not displaying after nav back // Reproduce steps: // 1. On app with multiple (overflown) tab items, Switch to the last tab item // 2. Navigate to a new page // 3. Nav back to the page with Tabs // 4. Notice the active last tab item is not showing. The tab strip is showing the most left / initial tab items instead. setTimeout(() => { this.mTabsBar.scrollToTab(this.selectedIndex); }, 0); } selectTabBar(oldIndex, newIndex) { this.mTabsBar.setSelectedPosition(newIndex); } setTabStripItems(items) { if (items?.length > 0 && !this.mUnSelectedItemColor) { items.some((item) => { const color = item.label?.style.color; if (color) { this.mUnSelectedItemColor = color; return true; } return false; }); } super.setTabStripItems(items); } willSelectWithoutAnimation(index) { this.mTabsBar?.forceTransitionToPosition(index); } onLoaded() { super.onLoaded(); if (!this.tabStrip && this.mTabsBar) { // manually set the visibility, so that the grid layout remeasures this.mTabsBar.setVisibility(android.view.View.GONE); } } }; Tabs = __decorate([ CSSType('Tabs') ], Tabs); export { Tabs }; //# sourceMappingURL=index.android.js.map