vi studio

Lessons · The language · 12 of 36

Events

on_tap, on_hold, on_touch, on_swipe, on_change, on_submit, on_hit.

An event runs an action when something happens to a container. A short action fits on the line; several actions go one per line underneath.

Event Runs when
on_tap it is tapped
on_hold it is pressed and held
on_touch a finger lands on it (at once, with no tap highlight: for games)
on_swipe a swipe: left:, right:, up:, down: underneath
on_change the text of an input changes
on_submit Enter / Done is pressed in an input
on_hit two containers start to overlap: a, b: action underneath (games)
taps = 0
last = "nothing yet"

main pad:
  arrange: center
  space_between: 12
  color: green[50]
  on_swipe:
    left: last = "swiped left"
    right: last = "swiped right"
  children:
    target:
      size: 40
      shape: circle
      color: green[700]
      arrange: center
      text: "{taps}"
      text_style: 36, bold, white
      on_tap: taps = taps + 1
      on_hold:
        taps = 0
        last = "held: back to zero"
    log:
      text: "Last: {last}"

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 The language

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.