@carployee/menu
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@carployee/menu

ns plugin add @carployee/menu

This plugin is an NS8 version of https://github.com/xlmnxp/nativescript-menu/blob/master/README.md All credits to @xlmnxp

A plugin that adds a pop-up menu to NativeScript

Installation

Demo

Android iOS
screenshot 1 screenshot 2

Usage

<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" class="page"
  xmlns:ui="nativescript-menu">
  <StackLayout class="p-20">
    <Button id="menuBtn" text="getMenu" tap="{{ buttonTap }}"/>
  </StackLayout>
</Page>
import { Menu } from 'nativescript-menu';

export class HelloWorldModel extends Observable {
	public message: string;
	private menu: Menu;

	constructor(public page: Page) {
		super();
	}

	buttonTap() {
		Menu.popup({
			view: this.page.getViewById('menuBtn'),
			actions: ['Example', 'NativeScript', 'Menu'],
		})
			.then((action) => {
				alert(action.id + ' - ' + action.title);
			})
			.catch(console.log);
	}
}

with custom options

import { Menu } from 'nativescript-menu';

export class HelloWorldModel extends Observable {
	public message: string;
	private menu: Menu;

	constructor(public page: Page) {
		super();
	}

	buttonTap() {
		Menu.popup({
			view: this.page.getViewById('menuBtn'),
			actions: [
				{ id: 'one', title: 'Example' },
				{ id: 'two', title: 'NativeScript', customOption: 'Hello' },
				{ id: 'three', title: 'Menu' },
			],
		})
			.then((action) => {
				alert(JSON.stringify(action));
			})
			.catch(console.log);
	}
}

API

  • MenuOptions
export interface MenuOptions {
	title?: string; // IOS Only
	message?: string; // IOS Only
	view: View;
	actions: object[] | string[];
	cancelButtonText?: string; // IOS Only
}
Method Description
popup(options: MenuOptions): Promise<{id: number, title: string} | actionObject | boolean> Create a pop-up menu and show it

Package Sidebar

Install

npm i @carployee/menu

Weekly Downloads

0

Version

1.0.1

License

Apache-2.0

Unpacked Size

24.3 kB

Total Files

13

Last publish

Collaborators

  • firetrip