App shell
The elements of the app's entry file:
AppMainBuilder
— a router over the screens,
AppRoute
— one screen,
AppContent
— the place where the shell shows the open screen.
RouteData
publishes which route is open and with which parameters — both the screens and the shell read it. The rules for sharing data between screens are in
Best practices: architecture
.
AppMainBuilder
The root of the app: a router over
AppRoute
. The first declared route opens. An optional child
@Macros id:shell
describes a persistent shell around the screens (navigation, background): it is mounted once and survives transitions — only the screen in place of the
child
mark changes.
Type:
multi-child
(
AppRoute
and
@Macros id:shell
)
AppMainBuilder title:"Shop"
AppRoute /home
AppRoute /catalog
@Macros id:shell
Scaffold
SizedBox.expand id:body child
| Parameter | Type | Default | Description |
|---|---|---|---|
title
|
string | — | The app's name for the system (window title, task switcher) |
cupertino
|
bool | false |
true
— an iOS-style app (screens on
CupertinoPageScaffold
); Material by default
|
@Macros id:shell
|
template | — |
The shell around the screens; the
child
mark is the place of the screen
|
The shell
gets no parameters
: it reads which route is open with the same
RouteData path:@…
as the screens.
AppMainBuilder title:"Shop"
AppRoute /home
AppRoute /catalog
@Macros id:shell
Scaffold
SizedBox.expand id:body child
RouteData path:@routePath
MapValue $routePath @tab "/home":0 "/catalog":1
NavigationBar id:bottomNavigationBar selectedIndex:$tab onDestinationSelected:(index){navigator.show(pick(index, "/home", "/catalog"))}
Icon id:destination label:"Home" home
Icon id:destination label:"Catalog" list
The outer
Scaffold
is in the shell and holds only the persistent parts (navigation, background); each screen has its own
Scaffold
with its own
AppBar
.
AppRoute
One screen:
AppRoute /catalog
shows the file
reeel/catalog.reeel
. It is written only inside
AppMainBuilder
; it draws nothing of its own.
Type:
leaf
(or nested
AppRoute
)
AppMainBuilder title:"Notes"
AppRoute /notes
AppRoute "/note/:id"
AppRoute /settings fullscreen:true
| Parameter | Type | Default | Description |
|---|---|---|---|
| (positional) | string | — |
The route path. A path with a parameter (
:id
) goes
in quotes
: without them
:
is read as a parameter separator
|
fullscreen
|
bool | false |
The screen takes the whole window, with no shell around it; the shell learns this through
RouteData fullscreen:@…
|
The screen's file is found by the static segments of the path:
"/note/:id"
→
reeel/note.reeel
.
Nesting is about the stack, not the address.
An
AppRoute
inside an
AppRoute
opens
on top of
its parent (not instead of it), so the system "back" gesture and the back button work. The nested route's path stays its own (
/note/:id
, not
/notes/note/:id
). Tabs that replace each other are declared as siblings.
AppContent
The open screen inside the shell.
Not written by hand
:
AppMainBuilder
puts it in place of the
child
mark in
@Macros id:shell
.
Type:
leaf
AppMainBuilder title:"App"
AppRoute /home
@Macros id:shell
Scaffold
SizedBox.expand id:body child
No parameters. In the shell's tree
AppContent
stands in place of
child
; outside
AppMainBuilder
it draws nothing.
RouteData
A generator: publishes the parameters of the open route into variables. It works on both sides of the navigator — on the route's screen and in the shell above it.
Type:
wrapper
// main.reeel: AppRoute "/detail/:id"
// navigation: navigator.show($"/detail/${item['id']}", item)
RouteData id:@productId extra:@product
Text {product['title'] ?? $"Product ${productId}"}
| Parameter | Type | Default | Description |
|---|---|---|---|
name:@variable
|
output | — |
A route path parameter:
id:@productId
for
"/detail/:id"
. Numbers arrive as integers — usable as a list index
|
extra
|
output
@name
|
— |
The object passed as the second argument of
navigator.show(path, extra)
. Present only on navigation inside the app; on a direct visit it is empty
|
path
|
output
@name
|
— |
Which
route is open — the static path (
/detail/:id
→
/detail
): the shell uses it to highlight the navigation item
|
fullscreen
|
output
@name
|
— |
Whether the open route asked for the whole window (
AppRoute … fullscreen:true
)
|
query
|
output
@name
|
— |
The address's
query string
parameters as a map:
?ref=abc
→
{'ref': 'abc'}
|
query
is neither the path parameters nor
extra
: they are named by whoever wrote the link (a referral code, a campaign tag, a return address); the route knows nothing about them.
RouteData query:@q
Text {q['ref'] ?? "no tag"}
The shell decides whether to draw itself by
fullscreen
:
RouteData fullscreen:@whole
Visibility visible:{!whole}
Text "Sidebar"
A variable the file has not declared is always an error: if the path is not read by
RouteData
, it has nowhere to come from.
Differences between the app and the site
-
The site has no app shell.
AppMainBuilderandAppRoutedraw nothing on the site; the project's site opens the screen of the firstAppRouteas a page.@Macros id:shellandAppContenttake no part on the site. -
On the site
RouteDataunderstands onlyquery: a static page has no route table. Path parameters,extra,pathandfullscreendo not work on the site: the editor warns about them rather than publishing them empty.
See also
-
Best practices: architecture
— data between screens, the double
Scaffold, path = file -
Data generators
—
MapValuefor the tab index -
Chain and Macros
—
@Macrosand thechildmark