Skip to content

Toolbar

iOS UIToolbar for NativeScript with first-class UIBarButtonItem and UIToolbarAppearance support.

The plugin supports:

  • Native iOS UIToolbar rendering
  • Descriptor-based toolbar items with tap callbacks
  • Native item escape hatch (UIBarButtonItem)
  • SF Symbols and image-based item icons
  • iOS 13+ appearance customization (UIToolbarAppearance)
  • iOS 14+ menu and primary action support on items
  • Android no-op placeholder so apps can install cross-platform without runtime errors

Installation

bash
npm install @nstudio/nativescript-toolbar

Usage

NativeScript Core (programmatic)

typescript
import { Color, EventData, Page } from '@nativescript/core';
import {
  NToolbar,
  ToolbarItem,
  ToolbarItemTapEventData,
} from '@nstudio/nativescript-toolbar';

export function navigatingTo(args: EventData) {
  const page = args.object as Page;

  const toolbar = new NToolbar();
  toolbar.height = 44;
  toolbar.barStyle = 'default';
  toolbar.translucent = true;
  toolbar.tintColor = new Color('#2563eb');

  const items: ToolbarItem[] = [
    { id: 'add', systemItem: 'add', onTap: () => console.log('Add') },
    { systemItem: 'flexibleSpace' },
    { id: 'edit', title: 'Edit', style: 'plain', onTap: () => console.log('Edit') },
    { systemItem: 'fixedSpace', width: 8 },
    { id: 'settings', systemImage: 'gearshape', onTap: () => console.log('Settings') },
  ];

  toolbar.setItems(items, true);

  toolbar.on(NToolbar.itemTapEvent, (event: ToolbarItemTapEventData) => {
    console.log('Tapped index:', event.data.index);
    console.log('Tapped id:', event.data.item?.id);
  });

  page.content = toolbar;
}

Angular

typescript
import { registerElement } from '@nativescript/angular';
import { NToolbar } from '@nstudio/nativescript-toolbar';

registerElement('NToolbar', () => NToolbar);
html
<NToolbar
  #toolbar
  height="44"
  barStyle="default"
  translucent="true"
  tintColor="#2563eb"
  (loaded)="onToolbarLoaded($event)"
  (itemTap)="onToolbarTap($event)">
</NToolbar>
typescript
import { Component } from '@angular/core';
import { EventData } from '@nativescript/core';
import {
  NToolbar,
  ToolbarItem,
  ToolbarItemTapEventData,
} from '@nstudio/nativescript-toolbar';

@Component({
  selector: 'demo-toolbar',
  templateUrl: './demo-toolbar.component.html',
})
export class DemoToolbarComponent {
  onToolbarLoaded(args: EventData) {
    const toolbar = args.object as NToolbar;
    const items: ToolbarItem[] = [
      { id: 'compose', systemItem: 'compose' },
      { systemItem: 'flexibleSpace' },
      { id: 'publish', title: 'Publish', style: 'done' },
      { systemItem: 'fixedSpace', width: 8 },
      { id: 'filters', systemImage: 'slider.horizontal.3' },
    ];
    toolbar.setItems(items, true);
  }

  onToolbarTap(args: ToolbarItemTapEventData) {
    console.log('Tapped:', args.data.item?.id ?? args.data.index);
  }
}

Other Flavors

typescript
import { NToolbar } from '@nstudio/nativescript-toolbar';

// Vue
registerElement('NToolbar', () => NToolbar);

// React
registerElement('nToolbar', () => NToolbar);

// Svelte
registerNativeViewElement('nToolbar', () => NToolbar);

// Solid
registerElement('nToolbar', NToolbar);

API

Class

  • NToolbar extends NativeScript View

Properties

PropertyTypeDescription
itemsToolbarItem[]Current toolbar item descriptors
barStyle'default' | 'black' | 'blackOpaque' | 'blackTranslucent' | numberiOS bar style
translucentbooleanWhether the toolbar is translucent
barTintColorstring | Color | UIColorToolbar background tint
tintColorstring | Color | UIColorDefault item tint
position'any' | 'bottom' | 'top' | 'topAttached' | numberBackground/shadow position metrics
defaultMetrics'default' | 'compact' | 'defaultPrompt' | 'compactPrompt' | 'landscapePhone' | 'landscapePhonePrompt' | numberBackground image metrics
itemChangesAnimatedbooleanWhether item changes animate by default
standardAppearanceToolbarAppearanceiOS 13+ standard appearance
compactAppearanceToolbarAppearanceiOS 13+ compact appearance
scrollEdgeAppearanceToolbarAppearanceiOS 15+ scroll-edge appearance
compactScrollEdgeAppearanceToolbarAppearanceiOS 15+ compact scroll-edge appearance

Events

EventPayloadDescription
itemTapToolbarItemTapEventDataFired when a descriptor-backed tappable item is pressed

Methods

MethodDescription
setItems(items: ToolbarItem[], animated?: boolean): voidSets toolbar items
getNativeItems(): UIBarButtonItem[]Returns native toolbar items
getNativeItem(indexOrId: number | string): UIBarButtonItem | nullFinds a native item by index or descriptor id
setAppearance(slot, appearance): voidSets standard, compact, scrollEdge, or compactScrollEdge appearance
setBackgroundImage(image, position?, metrics?): voidSets a background image
getBackgroundImage(position?, metrics?): UIImage | nullGets a background image
clearBackgroundImage(position?, metrics?): voidClears a background image
setShadowImage(image, position?): voidSets a shadow image
getShadowImage(position?): UIImage | nullGets a shadow image
clearShadowImage(position?): voidClears a shadow image

ToolbarItem

ToolbarItem supports native and high-level item creation.

typescript
type ToolbarItem = {
  id?: number | string;
  nativeItem?: UIBarButtonItem;

  systemItem?: ToolbarSystemItem;
  title?: string;
  style?: 'plain' | 'bordered' | 'done' | 'prominent' | number;
  image?: string | ImageSource | UIImage;
  systemImage?: string;
  landscapeImagePhone?: string | ImageSource | UIImage;
  customView?: View | UIView | (() => View | UIView);

  width?: number;
  enabled?: boolean;
  tintColor?: string | Color | UIColor;
  tag?: number;
  accessibilityIdentifier?: string;

  menu?: UIMenu;
  primaryAction?: UIAction;

  changesSelectionAsPrimaryAction?: boolean;
  selected?: boolean;
  hidden?: boolean;
  springLoaded?: boolean;
  symbolAnimationEnabled?: boolean;

  onTap?: (args: ToolbarItemTapEventData) => void;
};

ToolbarSystemItem supports:

  • done, cancel, edit, save, add
  • flexibleSpace, fixedSpace
  • compose, reply, action, organize, bookmarks
  • search, refresh, stop, camera, trash
  • play, pause, rewind, fastForward
  • undo, redo, pageCurl, close, writingTools

image supports system symbol aliases in string form: sys://, sf://, and symbol://.

Appearance API (UIToolbarAppearance, iOS 13+)

typescript
toolbar.standardAppearance = {
  preset: 'opaque',
  backgroundColor: '#ffffff',
  shadowColor: '#e5e7eb',
  buttonAppearance: {
    normal: {
      titleTextAttributes: {
        foregroundColor: '#111827',
      },
    },
    highlighted: {
      titleTextAttributes: {
        foregroundColor: '#2563eb',
      },
    },
  },
};

toolbar.scrollEdgeAppearance = {
  preset: 'transparent',
  backgroundEffectStyle: 'systemThinMaterial',
};

ToolbarAppearance options include:

  • preset: 'default' | 'opaque' | 'transparent'
  • backgroundColor
  • backgroundEffectStyle (name or numeric UIBlurEffectStyle)
  • backgroundImage
  • backgroundImageContentMode
  • shadowColor
  • shadowImage
  • buttonAppearance
  • doneButtonAppearance
  • prominentButtonAppearance (when available on current OS/runtime)

Native Escape Hatch

For unsupported edge cases, create a native UIBarButtonItem and pass it through ToolbarItem.nativeItem.

Platform Notes

iOS

  • Fully implemented with native UIToolbar
  • Supports native items, descriptor mapping, appearance slots, and item events

Android

  • No-op placeholder implementation
  • Allows cross-platform installation and shared code without Android crashes

License

Apache License Version 2.0