All Projects → mukaschultze → nativescript-windowed-modal

mukaschultze / nativescript-windowed-modal

Licence: Apache-2.0 license
Consistent modals for Android and iOS

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to nativescript-windowed-modal

WhatsMyScore2-NativeScript
What's My Score App built with NativeScript + Angular 2 + TypeScript
Stars: ✭ 14 (-70.21%)
Mutual labels:  nativescript
nativescript-ng-shadow
Angular directive to apply shadows to native elements according to the elevation level guidelines of material design specification
Stars: ✭ 54 (+14.89%)
Mutual labels:  nativescript
nativescript-dev-webpack
A package to help with webpacking NativeScript apps.
Stars: ✭ 98 (+108.51%)
Mutual labels:  nativescript
nativescript-toolbox
A NativeScript module that is a composition of useful tools and helpers.
Stars: ✭ 54 (+14.89%)
Mutual labels:  nativescript
nativescript-ng2-drawer-seed
Nativescript template project with drawer support
Stars: ✭ 17 (-63.83%)
Mutual labels:  nativescript
texttospeech
Text to Speech NativeScript plugin for Android & iOS 📢
Stars: ✭ 44 (-6.38%)
Mutual labels:  nativescript
nativescript-store-update
No description or website provided.
Stars: ✭ 18 (-61.7%)
Mutual labels:  nativescript
nativescript-angular-web-starter
A starter project to create web and native mobile apps using nativescript and angular with single shared code base.
Stars: ✭ 47 (+0%)
Mutual labels:  nativescript
nativescript-dev-typescript
TypeScript support for NativeScript projects
Stars: ✭ 20 (-57.45%)
Mutual labels:  nativescript
nativescript-vue-rollup-template
A NativeScript template ready to roll with Vue.js and .vue files.
Stars: ✭ 39 (-17.02%)
Mutual labels:  nativescript
nativescript-swipe-layout
🎆
Stars: ✭ 21 (-55.32%)
Mutual labels:  nativescript
nativescript-loading-indicator
NativeScript Loading Indicator plugin
Stars: ✭ 48 (+2.13%)
Mutual labels:  nativescript
nativescript-menu
A plugin that adds a pop-up menu to NativeScript
Stars: ✭ 17 (-63.83%)
Mutual labels:  nativescript
nativescript-imagepicker
Imagepicker plugin supporting both single and multiple selection.
Stars: ✭ 103 (+119.15%)
Mutual labels:  nativescript
nativescript-numeric-keyboard
🔢 Replace the meh default number/phone keyboard with this stylish one
Stars: ✭ 33 (-29.79%)
Mutual labels:  nativescript
NativeScript-Status-Bar
A simple NativeScript plugin for controlling status bar visibility.
Stars: ✭ 15 (-68.09%)
Mutual labels:  nativescript
nativescript-image-filters
NativeScript plugin to apply filters to images
Stars: ✭ 30 (-36.17%)
Mutual labels:  nativescript
nativescript-webview-interface
Plugin for bi-directional communication between webView and android/ios
Stars: ✭ 87 (+85.11%)
Mutual labels:  nativescript
nativescript-apple-sign-in
Sign In With Apple, as seen on WWDC 2019, available with iOS 13
Stars: ✭ 37 (-21.28%)
Mutual labels:  nativescript
nativescript-fancy-calendar
Fancy calendar for NativeScript 😄 🍻
Stars: ✭ 21 (-55.32%)
Mutual labels:  nativescript

Nativescript Windowed Modal apple android

npm version npm downloads Build Status Nativescript Dependency Visitors

This plugin overrides the showModal() from nativescript, making modals look and behave the same on Android and iOS.

Installation

tns plugin add nativescript-windowed-modal

Usage

Code

Call the overrideModalViewMethod() once before starting the app and register the layout element:

Javascript

var windowedModal = require("nativescript-windowed-modal")
windowedModal.overrideModalViewMethod()

Typescript+Angular

import { ExtendedShowModalOptions, ModalStack, overrideModalViewMethod } from "nativescript-windowed-modal"

overrideModalViewMethod()
registerElement("ModalStack", () => ModalStack)

You can pass extended options like this:

mainPage.showModal("./modal", {
  context: "I'm the context",
  closeCallback: (response: string) => console.log("Modal response: " + response),
  dimAmount: 0.5 // Sets the alpha of the background dim
} as ExtendedShowModalOptions)

NativeScript-Vue

// main.js
import { ModalStack, overrideModalViewMethod, VueWindowedModal } from "nativescript-windowed-modal"

overrideModalViewMethod()
Vue.registerElement("ModalStack", () => ModalStack)
Vue.use(VueWindowedModal)

You can pass extended options like this:

<script type="text/javascript">
  export default {
    methods: {
      openModalTap() {
        this.$showModal("./modal", {
          props: {},
          fullscreen: false,
          animated: true,
          stretched: false,
          dimAmount: 0.5 // Sets the alpha of the background dim,
        })
      }
    }
  }
</script>

Properties

ExtendedShowModalOptions

Property Type Platform Default Description
dimAmount? number both 0.5 Controls the alpha value of the dimming color. On Android, setting this to 0 disables the fade in animation. On iOS this value will be replaced with the alpha of the background color if it is set.

ModalStack

Property Type Platform Default Description
dismissEnabled boolean both true If set to true, the modal is allowed to close when touching outside of the content frame
verticalPosition string both middle Uses the same options as VerticalAlignment ("top" - "middle" - "bottom" - "stretch")
horizontalPosition string both center Uses the same options as HorizontalAlignment ("left" - "center" - "right" - "stretch")

Layout

Wrap your modal component with a ModalStack tag to layout the elements in a consistent way across platforms, it will also allows you to dismiss the modal when touching outsite of the frame:

XML

<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:modal="nativescript-windowed-modal">
    <modal:ModalStack dismissEnabled="true" class="modal-container">
        <StackLayout class="modal">
            <Label text="Hi, I'm your modal" class="text-center" textWrap="true"/>
        </StackLayout>
    </modal:ModalStack>
</Page>

HTML (Angular)

<ModalStack dismissEnabled="true" class="modal-container">
  <StackLayout class="modal">
    <Label text="Hi, I'm your modal" class="text-center" textWrap="true"></Label>
  </StackLayout>
</ModalStack>

Style

You may want to create the .modal and .modal-container classes in your .css to set margins, aligment and background color:

.modal {
  margin: 20;
  margin-top: 35;
  border-radius: 8;
  horizontal-align: center;
  vertical-align: middle;
  background-color: white;
}

.modal-container {
  padding: 25;
  padding-bottom: 10;
}

Running the demo app

  1. Clone this repo
  2. cd src
  3. npm run demo.android, npm run demo.ios, npm run demo.ng.android, or npm run demo.ng.ios

Known Issues

  • Padding won't apply on children of the ModalStack, wrapping them with a StackLayout fixes the problem;
  • Auto width is kinda buggy on some situations, set a fixed width for children of ModalStack when possible;

License

Apache License Version 2.0, January 2004

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].