@nativescript-community/ui-material-bottomsheet
TypeScript icon, indicating that this package has built-in type declarations

7.2.68 • Public • Published

NativeScript Material Bottom sheet

Material Design's Bottom sheet component for NativeScript.

npm npm

Contents

  1. Installation
  2. Changelog
  3. FAQ
  4. Usage

Installation

For NativeScript 7.0+

  • tns plugin add @nativescript-community/ui-material-bottomsheet

For NativeScript 6.x

  • tns plugin add nativescript-material-bottomsheet

If using tns-core-modules

  • tns plugin add nativescript-material-bottomsheet@2.5.4

Be sure to run a new build after adding plugins to avoid any issues.

API

export interface BottomSheetOptions {
    view: string | ViewBase; 
    // View instance to be shown in bottom sheet. Or the name of the module to load starting from the application root.
    context?: any; 
    // Any context you want to pass to the view shown in bottom sheet. This same context will be available in the arguments of the shownInBottomSheet event handler.
    animated?: boolean; 
    // An optional parameter specifying whether to show the sheet view with animation.
    dismissOnBackgroundTap?: boolean; 
    // An optional parameter specifying whether to dismiss the sheet when clicking on background.
    dismissOnDraggingDownSheet?: boolean; 
    // An optional parameter specifying whether to disable dragging the sheet to dismiss.
    dismissOnBackButton?: boolean; 
    // An optional parameter that specifies whether to close the sheet when pressing the back button.
    closeCallback?: Function; 
    //  A function that will be called when the view is closed. Any arguments provided when calling shownInBottomSheet.closeCallback will be available here.
    trackingScrollView?: string; 
    // optional id of the scroll view to track
    transparent?: boolean; 
    // optional parameter to make the bottomsheet transparent
    ignoreTopSafeArea?: boolean; 
    // optional ios parameter to top safe area. Default is true
    ignoreBottomSafeArea?: boolean; 
    // optional ios parameter to bottom safe area. Default is false
    disableDimBackground?: boolean; 
    // optional parameter to remove the dim background
    skipCollapsedState?: boolean; 
    // optional Android parameter to skip midway state when view is greater than 50%. Default is false
    peekHeight?: number; 
    // optional parameter to set the collapsed sheet height. To work on iOS you need to set trackingScrollView. Also ensure the scrollView is taking the full height of the bottomsheet content. Otherwise the "full" height wont be computed correctly
    ignoreKeyboardHeight?: boolean; 
    //(iOS only) A Boolean value that controls whether the height of the keyboard should affect the bottom sheet's frame when the keyboard shows on the screen. (Default: true)
    onChangeState?: onChangeStateBottomSheet; 
    // One works to be called on the scroll of the sheet. Parameters: state (CLOSED, DRAGGING, DRAGGING, COLLAPSED) and slideOffset is the new offset of this bottom sheet within [-1,1] range. Offset increases as this bottom sheet is moving upward. From 0 to 1 the sheet is between collapsed and expanded states and from -1 to 0 it is between hidden and collapsed states.
    canTouchBehind?: boolean //(Android only) allows to interact with the screen behind the sheet. For it to work properly need dismissOnBackgroundTap set to true.
}

Usage

Plain NativeScript

We need to do some wiring when your app starts, so open app.js and add this before creating any View/App/Frame:

JavaScript

var material = require("@nativescript-community/ui-material-bottomsheet");

material.install();

TypeScript

import { install } from "@nativescript-community/ui-material-bottomsheet";
install();

Uses the same kind of API as NativeScript Modals.

TS

const modalViewModulets = "ns-ui-category/modal-view/basics/modal-ts-view-page";
export function openBottomSheet(args) {
    const mainView: Button = <Button>args.object;
    const context = { username: "test_username", password: "test" };
    const fullscreen = true;
    mainView.showBottomSheet({
        view: modalViewModulets,
        context,
        closeCallback: (username, password) => {
            bottom-sheet
            alert(`Username: ${username} : Password: ${password}`);
        },
        fullscreen
    });
}

NativeScript + Vue 2

import Vue from 'nativescript-vue';
import BottomSheetPlugin from '@nativescript-community/ui-material-bottomsheet/vue';
import { install } from "@nativescript-community/ui-material-bottomsheet";
install();

Vue.use(BottomSheetPlugin);

Then you can show a Vue component:

import MyComponent from 'MyComponent.vue';

//inside another Vue component
const options: VueBottomSheetOptions = {
    // props to be passed to MyComponent
    props: {
        someProp: true,
        anotherProp: false
    },
    // listeners to be connected to MyComponent
    on: {
        someEvent: (value) => { console.log(value) }
    }
};
this.$showBottomSheet(MyComponent, options)

NativeScript + Vue 3

import { createApp } from 'nativescript-vue';
import { BottomSheetPlugin } from '@nativescript-community/ui-material-bottomsheet/vue3';
import { install } from "@nativescript-community/ui-material-bottomsheet";
install();

const app = createApp(...);
app.use(BottomSheetPlugin);

Then you can show a Vue component:

import { useBottomSheet } from "@nativescript-community/ui-material-bottomsheet/vue3";
import MyComponent from 'MyComponent.vue';


const options: VueBottomSheetOptions = {
    // props to be passed to MyComponent
    props: {
        someProp: true,
        anotherProp: false
    },
    // listeners to be connected to MyComponent
    on: {
        someEvent: (value) => { console.log(value) }
    }
};

const { showBottomSheet, closeBottomSheet } = useBottomSheet()

showBottomSheet(MyComponent, options);
closeBottomSheet();

NativeScript + Angular

First you need to include the NativeScriptMaterialBottomSheetModule in your app.module.ts

import { NativeScriptMaterialBottomSheetModule} from "@nativescript-community/ui-material-bottomsheet/angular";

@NgModule({
    imports: [
        // This will call the install method and inject a global service called BottomSheetService
        NativeScriptMaterialBottomSheetModule.forRoot()
    ],
    ...
})

now you can show your custom BottomSheet using the BottomSheetService, this service follows the same implementation as the ModalService

ItemComponent

import { Component,  ViewContainerRef } from '@angular/core';
import { BottomSheetOptions, BottomSheetService } from '@nativescript-community/ui-material-bottomsheet/angular';
import { ShareOptionsComponent } from './share-options.component';

@Component({
    selector: 'ns-item',
    templateUrl: './item.component.html',
    moduleId: module.id
})
export class ItemComponent {
    constructor(
        private bottomSheet: BottomSheetService, 
        private containerRef: ViewContainerRef,
    ) {}

    showOptions() {
        const options: BottomSheetOptions = {
            viewContainerRef: this.containerRef,
            context: ['Facebook', 'Google', 'Twitter']
        };

        this.bottomSheet.show(ShareOptionsComponent, options).subscribe(result => {
            console.log('Option selected:', result);
        });
    }
}

ShareOptionsComponent

<ListView
    [items]="options"
    (itemTap)="onTap($event)"
    separatorColor="white"
    class="list-group"
    height="200"
>
    <ng-template let-option="item">
        <Label
            class="list-group-item"
            [text]="option"
        ></Label>
    </ng-template>
</ListView>
import { Component, OnInit } from '@angular/core';
import { BottomSheetParams } from '@nativescript-community/ui-material-bottomsheet/angular';
import { ItemEventData } from '@nativescript/core/ui/list-view';

@Component({
    selector: 'ns-share-options',
    templateUrl: 'share-options.component.html'
})
export class ShareOptionsComponent implements OnInit {
    options: string[];
    
    // The BottomSheetService injects the BottomSheetParams to the component
    // so you can get the context and call the closeCallback method from the component displayed in your BottomSheet
    constructor(private params: BottomSheetParams) {}

    ngOnInit() {
        this.options = this.params.context;
    }

    onTap({ index }: ItemEventData) {
        this.params.closeCallback(this.options[index]);
    }
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
7.2.68117latest
5.0.82rc
4.0.32rc-esm
6.2.14-alpha.11alpha

Version History

VersionDownloads (Last 7 Days)Published
7.2.68117
7.2.67286
7.2.665
7.2.651
7.2.642
7.2.631
7.2.623
7.2.6199
7.2.601
7.2.591
7.2.581
7.2.571
7.2.561
7.2.551
7.2.541
7.2.531
7.2.521
7.2.501
7.2.491
7.2.481
7.2.471
7.2.461
7.2.4519
7.2.4447
7.2.430
7.2.420
7.2.410
7.2.400
7.2.380
7.2.360
7.2.350
7.2.340
7.2.320
7.2.300
7.2.290
7.2.280
7.2.270
7.2.260
7.2.250
7.2.240
7.2.2319
7.2.220
7.2.2199
7.2.207
7.2.197
7.2.187
7.2.179
7.2.164
7.2.154
7.2.143
7.2.133
7.2.124
7.2.1125
7.2.93
7.2.83
7.2.72
7.2.62
7.2.52
7.2.457
7.2.35
7.2.11
7.2.01
7.1.460
7.1.3199
7.1.21
7.1.11
7.1.01
7.0.421
7.0.411
7.0.401
7.0.391
7.0.371
7.0.361
7.0.351
7.0.344
7.0.331
7.0.321
7.0.311
7.0.3052
7.0.2967
7.0.2836
7.0.271
7.0.261
7.0.2526
7.0.241
7.0.231
7.0.221
7.0.211
7.0.201
7.0.191
7.0.181
7.0.171
7.0.161
7.0.151
7.0.141
7.0.131
7.0.121
7.0.111
7.0.101
7.0.91
7.0.81
7.0.71
7.0.61
7.0.51
7.0.41
7.0.31
7.0.21
7.0.13
7.0.01
6.2.24133
6.2.201
6.2.192
6.2.181
6.2.171
6.2.161
6.2.151
6.2.1410
6.2.14-alpha.11
6.2.14-alpha.01
6.2.131
6.2.121
6.2.111
6.2.101
6.2.91
6.2.81
6.2.71
6.2.61
6.2.51
6.2.439
6.2.391
6.2.249
6.2.12
6.2.02
6.1.23
6.1.12
6.1.02
6.0.68
6.0.522
6.0.42
6.0.32
6.0.22
6.0.12
6.0.02
5.3.2128
5.3.202
5.3.199
5.3.182
5.3.172
5.3.162
5.3.152
5.3.142
5.3.132
5.3.122
5.3.112
5.3.103
5.3.92
5.3.82
5.3.72
5.3.62
5.3.52
5.3.42
5.4.0-alpha.41
5.3.32
5.3.22
5.3.03
5.2.312
5.2.302
5.2.292
5.2.282
5.2.272
5.2.262
5.2.252
5.2.242
5.2.232
5.2.222
5.2.212
5.2.202
5.2.192
5.2.182
5.2.172
5.2.162
5.2.152
5.2.142
5.2.132
5.2.122
5.2.112
5.2.107
5.2.92
5.2.82
5.2.72
5.2.52
5.2.32
5.2.22
5.2.12
5.2.02
5.1.166
5.1.152
5.1.142
5.1.122
5.1.112
5.1.102
5.1.92
5.1.82
5.1.72
5.1.62
5.1.52
5.1.42
5.1.32
5.1.12
5.0.302
5.0.292
5.0.282
5.0.272
5.0.262
5.0.252
5.0.242
5.0.232
5.0.222
5.0.212
5.0.202
5.0.192
5.0.182
5.0.172
5.0.162
5.0.142
5.0.132
5.0.122
5.0.112
5.0.102
5.0.92
5.0.82
5.0.72
5.0.62
5.0.52
5.0.42
5.0.32
5.0.22
5.0.12
5.0.02
4.0.122
4.0.112
4.0.102
4.0.92
4.0.82
4.0.62
4.0.52
4.0.42
4.0.32
4.0.22
4.0.12
4.0.02
3.2.202

Package Sidebar

Install

npm i @nativescript-community/ui-material-bottomsheet

Weekly Downloads

670

Version

7.2.68

License

Apache-2.0

Unpacked Size

154 kB

Total Files

37

Last publish

Collaborators

  • classicoldsong
  • asharghi
  • farfromrefuge
  • triniwiz
  • eddyverbruggen
  • rigor789
  • walkerrunpdx
  • dnr
  • keerl
  • cvietor
  • bradmartin
  • rdlabo
  • tralves
  • cjohn001
  • jcassidyav
  • sebjean
  • edusperoni
  • ammarahm-ed
  • mayerlench
  • dgmachado