NativeScript 自定义底部菜单
NativeScript 自定义底部菜单是一个插件,可以显示一个自定义的美丽操作表/底部菜单。
npm i --save nativescript-custom-bottomsheet

NativeScript 自定义底部菜单 apple android

npm npm Build Status

概述

NativeScript 自定义底部菜单是一个插件,可以显示一个自定义的美丽操作表/底部菜单。

安装

tns plugin add nativescript-custom-bottomsheet

用法

TypeScript

xml

...
<StackLayout class="p-20">
<Button text="show" class="t-20 text-center c-black" tap="{{ onTap }}"/>
</StackLayout>
...

main-view-model.ts

import { Observable } from 'tns-core-modules/data/observable';
import { CustomBottomsheet, CBSheetOption } from 'nativescript-custom-bottomsheet';

export class HelloWorldModel extends Observable {
private customBottomsheet: CustomBottomsheet;

constructor() {
super();
this.customBottomsheet = new CustomBottomsheet();
}

public onTap(): void {
const options: CBSheetOption = {
icon: 'contact',
title: 'John Doe',
items: [{
icon: 'call',
title: 'Make a call'
},
{
icon: 'sms',
title: 'Send a text message'
},
{
icon: 'email',
title: 'Send an email'
},
{
icon: 'comments',
title: 'Leave a comment'
},
{
icon: 'delete',
title: 'Delete contact'
}
],
onItemTap: (index, item) => {
console.log('index', index);
},
cancelButtonText: 'Cancel'
};

this.customBottomsheet.show(options);
}
}

Angular

your.component.html

<GridLayout class="page">
<StackLayout class="p-20">
<Button text="show" class="t-20 text-center c-black" (tap)="onTap()"></Button>
</StackLayout>
</GridLayout>

your.component.ts

import { Component, OnInit } from "@angular/core";
import { OnTabSelectedEventData, BubbleNavigationItem } from 'nativescript-custom-bottomsheet';

@Component({
...
})
export class YourComponent implements OnInit {
private customBottomsheet: CustomBottomsheet;

constructor() {
this.customBottomsheet = new CustomBottomsheet();
}

ngOnInit(): void {
...
}

public onTap(): void {
const options: CBSheetOption = {
icon: 'contact',
title: 'John Doe',
items: [{
icon: 'call',
title: 'Make a call'
},
{
icon: 'sms',
title: 'Send a text message'
},
{
icon: 'email',
title: 'Send an email'
},
{
icon: 'comments',
title: 'Leave a comment'
},
{
icon: 'delete',
title: 'Delete contact'
}
],
onItemTap: (index, item) => {
console.log('index', index);
}
cancelButtonText: 'Cancel'
};

this.customBottomsheet.show(options);
}
}

Vue

app.js

your-component.vue

<template>
<Page class="page">
...

<GridLayout>
<StackLayout class="p-20">
<Button text="show" class="t-20 text-center c-black" @tap="onTap"></Button>
</StackLayout>
</GridLayout>
</Page>
</template>

<script>
import {
CustomBottomsheet
} from "nativescript-custom-bottomsheet";

const customBottomsheet = new CustomBottomsheet();

export default {
methods: {
onTap() {
const options = {
icon: "contact",
title: "John Doe",
items: [
{
icon: "call",
title: "Make a call"
},
{
icon: "sms",
title: "Send a text message"
},
{
icon: "email",
title: "Send an email"
},
{
icon: "comments",
title: "Leave a comment"
},
{
icon: "delete",
title: "Delete contact"
}
],
onItemTap: (index, item) => {
console.log("index", index);
},
cancelButtonText: 'Cancel'
};

this.customBottomsheet.show(options);
}
}
};
</script>

API

CustomBottomsheet

方法

属性 类型 描述 平台
show(options: CBSheetOption) 显示底部菜单 android apple

CBSheetOption

属性

属性 类型 描述 平台
icon 字符串 设置底部菜单标题图标 android apple
title 字符串 设置底部菜单标题 android apple
items Array 设置底部菜单项的图标和标题 android apple
onItemTap 回调函数 当点击项时调用,并传递点击项的索引及其属性(例如 icon 和 title) android apple
cancelButtonText 字符串 在 iOS 上设置取消按钮的文本 apple

CBSheetItem

属性

属性 类型 描述 平台
icon 字符串 设置底部菜单项图标 android apple
title 字符串 设置底部菜单项标题 android apple

限制

iOS

目前,在 iOS 上添加超过四个标签会导致文本动画被截断。

作者

Jonathan Mayunga,[email protected]

致谢

许可证

Apache 许可证版本 2.0,2004 年 1 月