Lessons · Building apps · 21 of 36
Changing the screen
A dot for one change, a block for several; wait and animate.
There are two ways to change a container from code:
- A dot for one change:
score_label.color = red. - A block for several: the container's name, then the new attributes underneath.
main home:
arrange: center
space_between: 16
children:
light
switch
light:
size: 40
shape: circle
color: gray[300]
animate: 0.4 seconds
switch:
button: "Turn on for 2 seconds"
on_tap: blink()
blink():
light:
color: amber[400]
shadow: true
switch.text = "On…"
wait(2 seconds)
light:
color: gray[300]
shadow: false
switch.text = "Turn on for 2 seconds"
lightandswitchare top-level containers, soblink()reaches them by name (lesson Reaching other containers).wait(2 seconds)pauses the function; the rest of the app keeps running.animate: 0.4makes changes to size, place, colour,see_through,flipandtiltglide over 0.4 seconds instead of jumping.- Changing a variable that a container uses redraws it too: often that is all you need.
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.
- Containers that take valuescard(task): one container, many values.
- Repeating thingsrepeat: task in tasks, grids, index, x, y and .at().
- Reaching other containersInside names, parent.name and top-level names.
- 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.