vi studio

Lessons · Building apps · 17 of 36

Screens

go_to, go_back, transitions, and phone / tablet / desktop.

The main container is the first screen. Every other screen is a container you open with go_to(name); go_back() returns. Screens fill the phone and stay clear of the notch and the keyboard by themselves.

tasks = [{ name: "Buy milk", note: "Two litres" }, { name: "Call Sam", note: "About Friday" }]

main home:
  space_inside: 24
  space_between: 12
  children:
    first:
      button: tasks[0].name
      on_tap: go_to(details(tasks[0]))
    second:
      button: tasks[1].name
      on_tap: go_to(details(tasks[1]), fade)
    settings_button:
      button: "Settings"
      on_tap: go_to(settings, slide)

details(task):
  space_inside: 24
  space_between: 12
  children:
    title:
      text: task.name
      text_style: 28, bold
    note:
      text: task.note
    back:
      button: "Back"
      on_tap: go_back()

settings:
  arrange: center
  children:
    label:
      text: "Settings"
    back:
      button: "Back"
      on_tap: go_back()

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.