Preview 2.0 is now in Public Beta!
Read the Announcement
Note: You are on the beta version of our docs. This is a work in progress and may contain broken links and pages.

<RootLayout> is a layout container designed to be used as the primary root layout container for your app with a built-in API to easily control dynamic view layers. It extends a GridLayout so has all the features of a grid but enhanced with additional apis.

You can use getRootLayout() to get a reference to the root layout in your app from anywhere.

Usage

To use the RootLayout element, add it to a HTML file

Then in the ViewModel, get its reference and call the open() method on it to open a View instance of interest.

xml
<RootLayout height="100%" width="100%">
  <GridLayout height="100%">
    <Label
      verticalAlignment="center"
      textAlignment="center"
      text="MAIN CONTENT AREA"
    ></label>
  </GridLayout>
</RootLayout>
ts
// Open a dynamic popup
const view = this.getPopup('#EA5936', 110, -30)
getRootLayout()
  .open(view, {
    shadeCover: {
      color: '#000',
      opacity: 0.7,
      tapToClose: true,
    },
    animation: {
      enterFrom: {
        opacity: 0,
        translateY: 500,
        duration: 500,
      },
      exitTo: {
        opacity: 0,
        duration: 300,
      },
    },
  })
  .catch((ex) => console.error(ex))

// Close the dynamic popup
getRootLayout()
  .close(view, {
    opacity: 0,
    translate: { x: 0, y: -500 },
  })
  .catch((ex) => console.error(ex))

function getPopup(color: string, size: number, offset: number): View {
  const layout = new StackLayout()
  layout.height = size
  layout.width = size
  layout.marginTop = offset
  layout.marginLeft = offset
  layout.backgroundColor = color
  layout.borderRadius = 10
  return layout
}

Svelte

First, convert a Svelte component to a View instance:

ts
function createNativeView(component, props?: any) {
  const fragment = createElement('fragment')
  const viewInstance = new component({ target: fragment, props })
  const element = fragment.firstElement() as NativeViewElementNode<View>
  return { element, viewInstance }
}

Then, pass the View instance to the open() method.

ts
const nsView = createNativeView(TestComponent).element.nativeView

setTimeout(() => {
  getRootLayout()
    .open(nsView, {
      shadeCover: {
        color: '#000',
        opacity: 0.7,
        tapToClose: true,
      },
      animation: {
        enterFrom: {
          opacity: 0,
          translateY: 500,
          duration: 500,
        },
        exitTo: {
          opacity: 0,
          duration: 300,
        },
      },
    })
    .catch((ex) => console.error(ex))
})

Listening to a view closed event

To handle a closed view event, listen to the view's unloaded event.

ts
view.on(ViewBase.unloadedEvent, () => {
  // Do something
})

API

RootLayout

MethodReturns
open(view: View, options?: RootLayoutOptions)Promise<void>
close(view: View, exitTo?: TransitionAnimation)Promise<void>
bringToFront(view: View, animated?: boolean)Promise<void>
closeAll()Promise<void>
getShadeCover()View

For inherited See GridLayout.

getRootLayout()

ts
 rootLayout: : RootLayout = getRootLayout()

Returns the reference to the RootLayout in an HTML file


RootLayoutOptions

PropertyTypeDescription
shadeCoverShadeCoverOptionsOptional
animation{ enterFrom?: TransitionAnimation; exitTo?: TransitionAnimation}Optional: enterFrom is only applied if it's the first one to be opened.
exitFrom is only applied if it's the last one to be closed

ShadeCoverOptions

PropertyTypeDescription
opacitynumberOptional
colorstringOptional
tapToClosebooleanOptional
animation{ enterFrom?: TransitionAnimation; exitTo?: TransitionAnimation}Optional: enterFrom is only applied if it's the first one to be opened.
exitFrom is only applied if it's the last one to be closed
ignoreShadeRestorebooleanOptional

TransitionAnimation

PropertyTypeDescription
translateXnumberOptional
translateYnumberOptional
scaleXnumberOptional
scaleYnumberOptional
rotatenumberOptional: in degrees
opacitynumberOptional
durationnumberOptional : in milliseconds
curveCoreTypes.AnimationCurveOptional
Previous
GridLayout