UNPKG

@nativescript-community/ui-material-tabs

Version:

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

81 lines 4.09 kB
import { registerElement } from 'react-nativescript'; import { warn } from 'react-nativescript/dist/shared/Logger'; import { Tabs } from '..'; import { TabStrip } from '@nativescript-community/ui-material-core-tabs/tab-strip'; import { TabContentItem } from '@nativescript-community/ui-material-core-tabs/tab-content-item'; let installed = false; export function registerTabs(opts = {}) { const { enableDebugLogging = false } = opts; if (installed) { return; } registerElement('tabs', // @ts-ignore I can assure that this really does extend ViewBase () => Tabs, { // TODO: share the same NodeOps for both BottomNavigation and Tabs; they're identical as they both extend TabNavigationBase. nodeOps: { insert(child, parent, atIndex) { const tabs = parent.nativeView; if (child.nodeRole === 'tabStrip') { if (child.nativeView instanceof TabStrip) { tabs.tabStrip = child.nativeView; } else { if (enableDebugLogging) { warn(`Unable to add child "${child.nativeView.constructor.name}" as the tabStrip of <tabs> as it is not an instance of TabStrip.`); } } } else if (child.nodeRole === 'items') { if (child.nativeView instanceof TabContentItem === false) { if (enableDebugLogging) { warn(`Unable to add child "${child.nativeView.constructor.name}" to the items of <tabs> as it is not an instance of TabContentItem.`); } return; } const items = tabs.items || []; // Annoyingly, it's the consumer's responsibility to ensure there's an array there! if (typeof atIndex === 'undefined' || atIndex === items.length) { tabs._addChildFromBuilder('items', child.nativeView); } else { const itemsClone = items.slice(); itemsClone.splice(atIndex, 0, child.nativeView); tabs.items = itemsClone; } } else if (child.nodeRole === 'item') { if (enableDebugLogging) { warn(`Unable to add child "${child.nativeView.constructor.name}" to <tabs> as it had the nodeRole "item"; please correct it to "items".`); } } else { if (enableDebugLogging) { warn(`Unable to add child "${child.nativeView.constructor.name}" to <tabs> as it does not have a nodeRole specified; ` + 'please set a nodeRole of "tabStrip", or "items".'); } } }, remove(child, parent) { const tabs = parent.nativeView; if (child.nodeRole === 'tabStrip') { tabs.tabStrip = null; // Anything falsy should work. } else if (child.nodeRole === 'items') { tabs.items = (tabs.items || []).filter((i) => i !== child.nativeView); } else if (child.nodeRole === 'item') { if (enableDebugLogging) { warn(`Unable to remove child "${child.nativeView.constructor.name}" from <tabs> as it had the nodeRole "item"; please correct it to "items".`); } } else { if (enableDebugLogging) { warn(`Unable to remove child "${child.nativeView.constructor.name}" from <tabs> as it does not have a nodeRole specified; ` + 'please set a nodeRole of "tabStrip", or "items"'); } } } } }); installed = true; } //# sourceMappingURL=index.js.map