vi studio

Lessons · Building apps · 20 of 36

Reaching other containers

Inside names, parent.name and top-level names.

Code reaches a container by its name: title.text, score_label.color.

main home:
  space_inside: 24
  space_between: 12
  children:
    form
    preview

form:
  space_between: 8
  children:
    name_box:
      input: "Type a name"
    save:
      button: "Show it"
      on_tap: preview.text = "Saved: {name_box.text}"

preview:
  text: "Nothing saved yet"
  text_style: 18, gray[700]
  on_tap: preview.text = "Still typing: {form.name_box.text}"

Inside form, save reaches its sibling as name_box. preview is outside form, so it writes form.name_box.

Every example here runs in Vi Studio: open it in your browser (phones too) and press Start learning on the welcome page. Each code block there has a Try it button that runs it in the phone preview.

More in Building apps

About Vi. Vi is a free, open-source programming language for building real mobile apps. You describe each screen in plain words, and Vi compiles it to React Native (Expo) for Android, iOS and the web. Its editor, Vi Studio, runs on Windows, in any browser and on your phone, with the app running live as you type. Read more about Vi.