Lessons · The language · 11 of 36
Buttons, inputs and other kinds
button, input, search, icon, link and scrolling lists.
The attribute that names a kind of container also holds its main value:
| Write | You get |
|---|---|
button: "Save" |
a button with that label |
input: "Your name" |
a text field; the words show while it is empty. Read what was typed as name.text |
search: "Search songs" |
a search field |
icon: heart |
an icon; its size and colour come from text_style |
link: "https://…" |
opens the page when tapped |
arrange: column, scroll |
a list that scrolls |
greeting = "Type your name and press Enter"
main form:
space_inside: 24
space_between: 12
children:
name_box:
input: "Your name"
on_change: greeting = "Hello, {name_box.text}…"
on_submit: greeting = "Hello, {name_box.text}!"
message:
text: greeting
text_style: 18
row:
arrange: row, center
space_between: 8
children:
star:
icon: star
text_style: 28, amber[500]
more:
link: "https://example.com"
text: "Read more"
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
- Comments and names# comments, <# blocks #> and snake_case names.
- ContainersEverything on screen is a container; children one per line.
- Size and spacesize out of 100, and space_inside / between / around.
- Arrange and placeDirection, spot and spread; floating with place.
- Texttext and text_style.
- Colour, shape and imagesColours and shades, shape, shadow, see_through, outline, @images.
- Eventson_tap, on_hold, on_touch, on_swipe, on_change, on_submit, on_hit.
- Data: lists and objectsVariables, lists, objects and the list helpers.
- FunctionsYour own functions and the built-in ones.
- Conditions and loopsif / else, the inline if, and, or, not, for and while.
- Programs without a screenmain functions and print().
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.