1.1.3 • Published 8 months ago
@amj7/nativescript-vue-portal v1.1.3
PortalVue for NativeScript Vue 3
A Portal Component for NativeScript Vue 3, to render elements outside of a component, anywhere in your app.
Getting Started
Install the package:
npm i @amj7/nativescript-vue-portalRegister the plugin in your
main.ts(or equivalent):import { createApp } from 'vue' import Home from './components/Home.vue' import PortalVue from '@amj7/nativescript-vue-portal' const app = createApp(Home) PortalVue(app) app.start()This registers the necessary components and registers and App-level Provide for managing portal connections throughout your application.
Use the
PortalandPortalTargetcomponents in your App:<template> <Portal to="myDestination"> <label text="Hello from the Portal!" /> </Portal> <PortalTarget name="myDestination" /> </template>
Special Considerations
RootLayout:
The RootLayout will break vue events if we teleport multiple items in-and-out of it. To fix this, the wrap-prop was added to render all items within a GridLayout.
<Frame>
  <Page actionBarHidden="true">
    <RootLayout>
      <GridLayout>
        <!-- content -->
      </GridLayout>
      <PortalTarget name="destination" wrap multiple/>
    </RootLayout>
  </Page>
</Frame>To change the default wrap element, use the as-prop. (as="StackLayout")
Use without installing globally:
You can import the components directly. The first created instance of Portal or PortalTarget will try to register the required App-level Provide.
<script setup lang="ts">
import { PortalTarget } from '@amj7/nativescript-vue-portal'
</script>
<template>
  <PortalTarget name="destination" />
</template>API
<Portal>
Props:
to(String): The name of thePortalTargetwhere the content should be rendered.name(String | Symbol, default: Unique ID): A unique identifier for the portal. Defaults to a generated unique ID.disabled(Boolean, optional): Iftrue, the portal will be disabled and the content will not be rendered in the target, but will render in it's original position.order(Number, optional): Specifies the rendering order of the portal content within the target, especially useful when usingmultiple. Lower numbers render first.slotProps(Object, optional): Props that are passed to the slot content of the portal, when it's rendered in it's original position.
<PortalTarget>
Props:
name(String, required): The unique name that matches thetoprop of aPortal.wrap(Boolean, optional, default:false): Iftrue, wraps the rendered content in a layout element (specified by theasprop). Required when teleporting multiple items to aRootLayoutto avoid event issues.as(String, optional, default:GridLayout): The NativeScript layout element to use as the wrapper whenwrapistrue.multiple(Boolean, optional, default:false): Iftrue, allows multiplePortalcomponents to render content to thisPortalTarget.slotProps(Object, default:{}): Props that are passed to the slot content of the PortalTarget.
Emits:
change(returns{ hasContent: boolean, sources: Name[] }): Fires after items have been teleported in or out.