This plugin overrides the showModal()
from nativescript, making modals look and behave the same on Android and iOS.
tns plugin add nativescript-windowed-modal
Call the overrideModalViewMethod()
once before starting the app and register the layout element:
var windowedModal = require("nativescript-windowed-modal")
windowedModal.overrideModalViewMethod()
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)
// 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>
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. |
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") |
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:
<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>
<ModalStack dismissEnabled="true" class="modal-container">
<StackLayout class="modal">
<Label text="Hi, I'm your modal" class="text-center" textWrap="true"></Label>
</StackLayout>
</ModalStack>
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;
}
cd src
npm run demo.android
, npm run demo.ios
, npm run demo.ng.android
, or npm run demo.ng.ios
ModalStack
, wrapping them with a StackLayout
fixes the problem;ModalStack
when possible;Apache License Version 2.0, January 2004
NativeScript 可以使用 Javascript,CSS, XML 创建真正的 Native 跨平台应用,支持 iOS Android,NativeScript 将您的跨平台代码翻译成目标平台的代码。 UI 使用 XML 描述,CSS 样式,在编译时将 UI 转化成本地原生代码,最终得到正在的 Native 原生应用。 Telerik 公开了用于创建安卓、iOS和Windows Unive
NativeScript Command-Line Interface The NativeScript CLI lets you create, build, and deploy NativeScript-based apps on iOS and Android devices. Get it using: npm install -g nativescript What is Native
NativeScript-Snackbar �� �� �� NativeScript plugin for Material Design SnackBar component. Installation: NativeScript 7+:tns plugin add @nstudio/nativescript-snackbar NativeScript version prior to 7:t
Nativescript-Ripple This plugin aims to bring a native (or close to native) ripple implementation on Android and iOS. The android version uses a RippleDrawable and conserves the previous background, a
NativeScript-FloatingActionButton NativeScript plugin for Material Design Floating Action Button UI component. Installation Nativescript 7+: ns plugin add @nstudio/nativescript-floatingactionbutton Na
NativeScript CardView A NativeScript plugin to provide an XML widget to implement the Material Design CardView component. Installation NativeScript 7+: ns plugin add @nstudio/nativescript-cardview Nat