Lessons · Building apps · 24 of 36
Files and projects
src/, every file sees every name, one name in one file.
A small example fits in one file. A real app reads better when each file does one job. Every new project is laid out like this:
my-app/
README.md
assets/ icon.png, splash.png, your pictures and sounds
src/
main.vi the main screen: puts the pieces together
config.vi app name, icon, splash screen, store id
theme.vi colours used everywhere
tasks.vi the data, and the functions that change it
components/
header.vi one piece of the screen per file
task_row.vi
- Every file sees every name in the project. There are no imports between your own files:
src/main.vican showheaderfromsrc/components/header.vijust by naming it. - A name may be defined in one file only. Two files defining
headeris an error that names both files. src/main.viholds themaincontainer: that is where the app starts.- Hover a name, or press F12 on it (Go to Definition), to see which file it lives in.
- Code from the internet is the one thing you import, by address:
from "https://example.com/widgets.vi" import star_rating(coming soon).
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.
- 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.
- 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.