Design your own components
Use any component in a flow, and build your own in the designer, with content slots, components it is given, its own variables, events, lists and content that comes and goes.
A component is a piece you design once and use many times: a plan card, an accordion, a height picker. Change the component, and every copy of it changes. Components your developers write in code and components you design work the same way where you use them; they differ only in how their inside is made.
Designed components are in preview: they work and you can ship them, but they may still change, and you use them at your own risk.
Use a component
Add one from Components (⌘J): Custom lists the components of this flow, Code the ones the project installed or its developers wrote. Select the copy you placed, called an instance, to set it up in its Component section:
- Properties: a row per property. Type a value, or click Bind to a variable to connect it to one of the flow's variables. Properties go both ways: when the component changes a property, the variable it is bound to changes too. A row marked ⇄ is set by the component, and Σ is computed by it, such as whether it is valid; hover the mark to see where the value goes. A computed property can only be bound.
- Content rows hold layers you design inside the instance, such as an accordion's body. Open the row's menu and choose Add a layer, then design it in place. Use the default content removes yours.
- Component rows choose a component for the instance to show, such as the icon a grid repeats. Pick one from the list; only components with what it needs are listed. Click Edit to set the chosen component's other properties; the ones the receiving component sets show Given by ….
- Events, such as changed, are in Interaction → Events. Click one to open its steps in the step editor; each field the event carries, such as the wheel's new value, is a variable there. An event that does nothing yet can also run a shared action.
Create a component
- Design the piece on a screen, select it and press ⌥⌘K, or right-click it and choose Create component. The original becomes the first instance, and the component appears under Custom.
- To change the component itself, click Edit on its row in Custom. Edits apply to every instance.
- With the component selected, its panel has Details (description, category, icon), Properties, Variables, Computed, Events and Variants.
Properties
Click Add property and choose its kind: Text, Number, True or false, Option
(one of a few options), Product, List, Content or Component. Give it a name and a
default. Inside the component, a property reads like a variable: write {Title} in a text, test it
in a variant or a layer's Show when, or set it with an action.
A property can also drive a layer's look. Select the layer, and next to its width, height,
opacity, rotation, a colour or another style field, open its list of values (Variables for
width). The field then reads a property or variable instead of a fixed value and shows what it
reads; click it to change that. To work it out from several, such as the property times 100,
choose New computed at the end of the list (New variable makes a variable instead). For a
width or height, choose % of parent to read the number as a share of the layer around it. A
progress bar is a track with a fill inside whose width reads a computed progress × 100 in % of
parent: each instance gives its own progress, or binds it to a variable that a button changes.
Fixed width in the field's menu goes back to a fixed value. A variant that sets the same field wins while it
applies.
A Content property is a slot: the place where the person using the component puts their own layers. Select the view inside the component where it shows, and pick the property under Shows. The view's own layers show while an instance gives none.
A Component property is a component the instance chooses. Under Accepts, list what a chosen component must have (Add required property, and the events it must raise with the fields each carries), and pick a Default among the components that have it. To place it inside your component, open Components while you edit the component: its component properties are listed first, under Properties. Pick one and click where it should show, or drag it there, as with any component; the default is drawn there, and the placeholder's panel sets the properties it gives and binds its events. To show it several times, repeat the placeholder.
Variables
Variables are the component's own memory, such as whether an accordion is open. Each instance keeps its own, and nothing outside sees them. Click Add variable and pick its type. To share a value with the screen, make it a property instead.
Computed
Computed values are worked out from the component's properties and variables, such as feet and inches from a height in centimetres. Click Add computed and choose its type; its steps open in the step editor. Inside the component a computed value reads like a variable, and nothing sets it.
Actions
Actions are steps the component's events can share. Click Add action, then pick it with Use a shared action on an event inside the component.
Events
Events are what the component tells the screen, such as changed. Click Add event, name it, and add the fields it carries, such as the new height. Raise it with the Emit event action in the steps of an event inside the component; each instance decides what it does.
Variants
Variants change how the component looks while its properties hold given values, such as Selected while Selected is true. Click Add variant, add conditions under Applies when, then select the variant and restyle layers; the changes apply only to it.
Events and shared actions
In a flow with designed components, events open their steps in the step editor, which covers the designer until you close it; its settings for the steps are on its right:
- A layer's or an instance's Events, in Interaction → Events. + (Add event) adds one that starts empty, or that runs a shared action you pick.
- A screen's Events: + adds On appear, each time the screen is shown, again when the person comes back to it, or On disappear.
- The flow's Events, with nothing selected: + adds On start, once when the flow starts, or On close.
Each lists only the events you added. The steps of an event on a screen belong to that screen, so they can read and set its variables. An event whose action sets a variable of a layer, from a flow made earlier, keeps its popover until the variable is moved to the screen.
When several events run the same steps, the editor says Shared by N events, and a change applies to all of them; Make a copy for this event gives this one steps of its own. − beside an event removes it. Use a shared action lists the screen's actions under Screen and the flow's under Flow. Actions, after Computed in the flow's, each screen's and each component's panel, lists the shared actions: + (Add action) adds one, a row opens its steps, and − deletes it. An action's In, in the step editor, moves it between the flow and a screen.
A Purchase product or Restore purchases step can go on by how it ends: Purchased, Cancelled, Pending or Failed, besides Right away. See When a purchase doesn't go through.
Lists and content that comes and goes
A layer's Interaction → Render says whether it shows, and how many times. Click + and choose:
- Show when: the layer shows only while a condition holds, and takes no space otherwise; see Show a layer only sometimes.
- Repeat: the layer shows once per item of a list, or a number of times.
Repeat a layer
- Select the layer to repeat, such as a row, open Interaction → Render, click + and choose Repeat. It repeats over the first list it can read, or 3 times when there is none.
- Under For each, pick a list, or A number of times and set Times to a whole number or a number variable. The list or number is the flow's, or inside a component one of its properties or variables.
- Inside the layer, item (the list's item), index, first and last are variables:
write
{item}in a text, or give a divider inside it Show when last is false.
The layers list shows the layer inside a Repeat layer, which lays the copies out: it starts with the layout of the layer around it, and you change it in its Layout. On the canvas the copies follow the items the list starts with. Click any copy to edit the layer; every copy follows. A copy that stays in the list keeps what it holds, such as text typed into it, when items are added or removed around it. Stop repeating (− beside For each) shows the layer once again.
Flows made earlier with a Logic layer keep working. Select the layer and click Open to edit its render logic.
Examples
- A list of interests: a Row view showing
{item}, repeated for each item of the flow's interests list. - An accordion: a Title text property, a Body content property and an open variable. A press on the header sets open to the opposite: in its Set variable action, choose open and click Toggle; each press then flips it. The view that shows Body has Show when open is true. Each accordion opens on its own.
- A grid of icons: an items list and an icon component property that accepts a text label. Place icon in a view laid out as a wrapping row, repeat it for each item of items, and give its label the variable item. Choose any icon component with a label on the instance.
- A height picker in feet and inches: a height number property in centimetres, an
isValid property computed from it, and a wheel component property that accepts
options and values lists, a value text and a change event carrying a value
text; install
voidhash/wheelfrom the Voidhash library and make it the default. Place wheel twice in a row from Components, give each its options and values, and bind its value to a computed value worked out from height (feet, and inches). Each wheel's change sets height from the event's value and emits changed with it. On a screen, choose Wheel picker for wheel and set its Mode to Options, bind height to a variable and isValid to one that turns off the Continue button; another control that sets the height moves the wheels too.
If something's off
- A property can't be given a value: it is computed by the component. Bind it to a variable to read it.
- A component is missing from a Component row's list: it lacks something the property accepts, such as a label text property. Add it to that component, or change Accepts.
- A Repeat says "nothing to repeat yet": the list it repeats over is empty at first, or the number is 0. Give the list a few texts of its own.
- Repeat says the layer can't repeat: a screen, a layer on the canvas outside a screen, a component's own body and a layer that already repeats can't; the message says what to do instead.
- A text in a calculation counts as 0: a calculation reads text as the number it holds, and any other text as 0. A fixed text that is no number is flagged in the step editor.
- The flow won't build: Issues, in the left rail, lists each problem, such as a component that doesn't have what a property accepts.
Next steps
Still stuck? Check Troubleshooting, ask us on Discord, or email support@voidhash.com on a paid plan.
Something wrong or missing on this page? Tell us by email or on Discord.