Parsware
All articles

Parsware Platform

Components shared across screens

The Contact list app had a link or two in a different place on each of its four screens. Now it has one top bar, drawn once beside the screens, placed on all four, and changed in one place.

The Overview screen under a blue top bar reading Contact list · Overview, with Today, Contacts and Overview links on the right, next to the title "Components shared across screens"

The Contact list app now has four screens: Today, Contacts, Contact and Overview. Each one grew its own way to the others, a link here, a button there, in a different place each time. An app's screens should share a top bar, and a top bar drawn four times is four top bars that drift apart the first time one of them changes.

So draw it once, as a component, and place it on every screen.

1. Draw the bar beside the screens

With the Frame tool, draw a frame on bare canvas, to the right of the screens, and make it 1200 by 56. Name it Top bar. It isn't a screen: it's the drawing the screens will copy, so it lives off to the side.

Put four things in it: A paragraph on the left, and three of A link on the right, Today, Contacts and Overview.

The canvas zoomed onto the Top bar frame: a paragraph on the left and three links on the right, and Top bar, Where, Today link, Contacts link and Overview link in Layers

2. Say which screen this is

Every copy of the bar will be the same, but each one is on a different screen. The paragraph says which, by binding its Text:

"Contact list · " + screen.name

The code page for the paragraph: Text marked Written, with "Contact list · " + screen.name in the editor

screen.name is the name of whichever screen the bar is on. That's the only thing that differs from one copy to the next, and nobody has to set it.

3. Make it a component

Right-click the bar's empty middle and choose Make component. The inspector now says Component: Top bar, and Top bar is in the Components list:

The Top bar selected with the Component section in the inspector: Top bar, An overlay card unticked, and the States list

4. Place it on every screen

Select a screen, click Top bar in Components, and set the copy's X and Y to the screen's top-left corner. Do the same on the other three. Then delete the links each screen had before: Overview on Contacts, and All contacts on the other three.

The whole canvas: the four screens, each with the bar across its top, and the Top bar drawing to the right

A link that goes to another screen of the app takes the screen's name as its address. Type Overview, not /apps/new_contactlist/Overview:

The Screen tab for the Overview link: This object is A link, Address Overview, Opens In this window, and the hint that a screen's name goes to that screen wherever the app is opened

That matters in the next article, where the same screens open inside a model-driven app at a different address.

5. Make it stretch

The screens are drawn 1200 wide and fill whatever window they're opened in, so the bar should stretch with them. Select each copy and set its Horizontal constraint to Left & right:

The inspector for a placed copy: Instance Top bar, Go to main component, and Constraints Horizontal Left & right, Vertical Top

In the drawing, set the three links' Horizontal to Right, so they keep to the right edge of a wider bar (see Resize constraints).

Save, and open the app. The same bar is on every screen, each saying where you are:

The Today screen under the bar: Contact list · Today on the left, Today, Contacts and Overview on the right

The Contacts screen under the same bar, reading Contact list · Contacts

6. Change it once

Select the drawing, Top bar, and give it a Primary fill:

The Top bar drawing selected, now blue, with Component Top bar in the inspector

Save. Every screen's bar is blue now. You changed one drawing:

The Overview screen under a blue bar reading Contact list · Overview, with its tiles, donut and grid

What we fixed

Building the bar turned up two bugs in components, both now fixed:

  • A part's constraints didn't reach the copies. We pinned the links to the right in the drawing, and every placed bar kept them on the left, so a stretched bar had its links in the middle. A part's constraints now come from the drawing, like its position does.
  • Nor did its address. Changing a link's Address in the drawing changed it in the drawing only, and every copy kept linking where it used to. The same was true of a part's bindings and handlers. None of these can be changed on a copy, so they now always come from the drawing.

Try it

Import the Shared components sample (studio-shared-components). Its Products app draws a Stat card, and its Orders app places it: a component shared between two apps rather than two screens.

Next: a phone-sized screen, raised on a phone and approved on a desktop.