Navigation Drawer
This example shows how to create an app with a Navigation Drawer.
class MyApp extends App{
isDrawerOpen = false
createStartPage(){
return HomePage
}
openDrawer(){
a.isDrawerOpen = true
}
closeDrawer(){
a.isDrawerOpen = false
}
createLayout(pageContent){
const closeDrawerButton = Button.keepIf(a.isDrawerOpen).onClick(a.closeDrawer).text(`←`)
const openDrawerButton = Button.keepIf(!a.isDrawerOpen).onClick(a.openDrawer).text(`☰`)
const drawer = Columns.keepIf(a.isDrawerOpen).backgroundColor(`#77777777`).children(
Rows.backgroundColor(`white`).padding(2).children(
Button.onClick(a.closeDrawer).text(`Home`).page(HomePage),
Space.grow(0.01),
Button.onClick(a.closeDrawer).text(`About`).page(AboutPage),
Space.grow(0.01),
Button.onClick(a.closeDrawer).text(`Contact`).page(ContactPage),
Space,
),
Space,
)
return Rows.backgroundColor(`skyblue`).children(
Columns.border(1, `black`, `b`).children(
closeDrawerButton,
openDrawerButton,
Text.grow(1).text(`Sample App`)
),
Layers.grow(1).children(
pageContent,
drawer,
),
)
}
}
class HomePage extends Page{
createGui(){
return a.createLayout(
Text.text(`Home!`),
)
}
}
class AboutPage extends Page{
createGui(){
return a.createLayout(
Text.text(`About!`),
)
}
}
class ContactPage extends Page{
createGui(){
return a.createLayout(
Text.text(`Contact us!`),
)
}
}