@nativescript-community/ui-material-bottom-navigation
Version:
Material Design Bottom Navigation bars allow movement between primary destinations in an app. Tapping on a bottom navigation icon takes you directly to the associated view or refreshes the currently active view.
80 lines • 4.15 kB
JavaScript
import { registerElement } from 'react-nativescript';
import { warn } from 'react-nativescript/dist/shared/Logger';
import { BottomNavigation, TabContentItem, TabStrip } from '../';
let installed = false;
export function registerBottomNavigation(opts = {}) {
const { enableDebugLogging = false } = opts;
if (installed) {
return;
}
registerElement('bottomNavigation',
// @ts-ignore I can assure that this really does extend ViewBase
() => BottomNavigation, {
// TODO: share the same NodeOps for both BottomNavigation and Tabs; they're identical as they both extend TabNavigationBase.
nodeOps: {
insert(child, parent, atIndex) {
const bottomNavigation = parent.nativeView;
if (child.nodeRole === 'tabStrip') {
if (child.nativeView instanceof TabStrip) {
bottomNavigation.tabStrip = child.nativeView;
}
else {
if (enableDebugLogging) {
warn(`Unable to add child "${child.nativeView.constructor.name}" as the tabStrip of <bottomNavigation> 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 <bottomNavigation> as it is not an instance of TabContentItem.`);
}
return;
}
const items = bottomNavigation.items || []; // Annoyingly, it's the consumer's responsibility to ensure there's an array there!
if (typeof atIndex === 'undefined' || atIndex === items.length) {
bottomNavigation._addChildFromBuilder('items', child.nativeView);
}
else {
const itemsClone = items.slice();
itemsClone.splice(atIndex, 0, child.nativeView);
bottomNavigation.items = itemsClone;
}
}
else if (child.nodeRole === 'item') {
if (enableDebugLogging) {
warn(`Unable to add child "${child.nativeView.constructor.name}" to <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".`);
}
}
else {
if (enableDebugLogging) {
warn(`Unable to add child "${child.nativeView.constructor.name}" to <bottomNavigation> 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 <bottomNavigation> as it had the nodeRole "item"; please correct it to "items".`);
}
}
else {
if (enableDebugLogging) {
warn(`Unable to remove child "${child.nativeView.constructor.name}" from <bottomNavigation> as it does not have a nodeRole specified; ` +
'please set a nodeRole of "tabStrip", or "items"');
}
}
}
}
});
installed = true;
}
//# sourceMappingURL=index.js.map