Lessons · Getting started · 2 of 36
Vi in five minutes
Containers, data, functions and layout in four small apps.
main home:
color: blue[50]
arrange: center
children:
greeting:
text: "Hello!"
text_style: 32, bold, blue[700]
main home:is the screen the app opens on. Everything on screen is a container.- Each container has attributes, one per line:
name: value. children:lists what is inside, one per line. A child can be written right there (greeting:with its own attributes) or by name (a container defined elsewhere).arrange: centerputs the children in the middle.text_style: 32, bold, blue[700]is size, weight and colour, in any order.
Data makes the screen change
count = 0
main counter:
arrange: center
space_between: 16
children:
display:
text: "Count: {count}"
text_style: 32
plus:
button: "+ 1"
on_tap: count = count + 1
count = 0is a variable.{count}puts its value inside text.button: "+ 1"makes a button with that label.on_tap:runs when it is tapped.- When a variable changes, every container that uses it redraws by itself.
Functions do the work
tasks = ["Buy milk", "Call Sam"]
add_task(name):
tasks.add(name)
main home:
space_inside: 20
space_between: 10
children:
title:
text: "{tasks.count} tasks"
text_style: 24, bold
task_row
add:
button: "Add one"
on_tap: add_task("Task {tasks.count + 1}")
task_row:
repeat: task in tasks
size: max, auto
space_inside: 12
color: gray[100]
shape: rounded
text: task
on_hold: tasks.remove(task)
add_task(name):is a function: it has brackets after its name and holds statements.repeat: task in tasksdraws onetask_rowfor each item, and follows the list as it changes.on_holdruns on a long press: hold a row to remove it.
Sizes, space and layout
main home:
arrange: column, spread
space_inside: 24
children:
banner:
size: max, 30
color: purple[400]
shape: rounded
tiles:
size: max, auto
arrange: row, spread
children:
tile_a:
size: 30
color: orange[300]
tile_b:
size: 30
color: green[300]
tile_c:
size: 30
color: blue[300]
size: width, heightis out of 100 of the parent:size: max, 30is full width and 30 % of the parent's height. One number makes a square.maxfills,autofits the content.- Text sizes and spaces (
space_inside,space_between,space_around) are fixed points, so they look the same on every phone. arrange:sets the direction (row,column), the spot (center,top right…) and the spread (spreadputs the space between the children).
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 Getting started
- Welcome to ViWhat Vi is and how Vi Studio works.
- Your first appA complete counter app, line by line.
- Projects and templatesNew Project, Create blank project, and how a project is laid out.
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.