Lessons · Building apps · 18 of 36
Containers that take values
card(task): one container, many values.
A container can take values, like a function: write the names in brackets after its name, then
use them in its attributes. Show it with values: task_card(tasks[0]).
tasks = [{ name: "Buy milk", done: true }, { name: "Call Sam", done: false }]
main home:
space_inside: 20
space_between: 10
children:
task_card(tasks[0])
task_card(tasks[1])
task_card(task):
size: max, auto
space_inside: 14
shape: rounded
color: green[100] if (task.done) else white
shadow: true
text: task.name
text_style: strikethrough if (task.done) else normal
on_tap: task.done = not task.done
Containers written inside it see the values too, however deep:
main home:
children:
tab("🧳", "Trips")
tab("🗺️", "Map")
tab(emoji, label):
arrange: row
space_between: 6
children:
tab_icon:
text: emoji
tab_name:
text: label
text_style: 12, bold
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
- Screensgo_to, go_back, transitions, and phone / tablet / desktop.
- Repeating thingsrepeat: task in tasks, grids, index, x, y and .at().
- Reaching other containersInside names, parent.name and top-level names.
- Changing the screenA dot for one change, a block for several; wait and animate.
- Timers and gamesevery(), stop(), on_touch, place: x, y and on_hit.
- Sound and videoplay, loop, stop_sounds, audio and video.
- Files and projectssrc/, every file sees every name, one name in one file.
- The config blockApp name, store id, version, icon and splash screen.
- Errors and good habitsThe real error messages and their fixes; how to organise a project.
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.