KO
|
EN
gitlite โ search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
toolbar-demo
โ 10
Open GitHub โ
No description available.
Download README (.md)
Explore Similar Repositories
react-native-boilerplate
:
๐ฑ React Native Boilerplate
service-pipeline
:
Service packaging pipeline and coordination for StartOS
vite-vue3-prerender-demo
:
A prerender demo for Vue 3 base on Vite.
springfox-swagger-xss
:
PoC for XSS springfox-swagger-ui 2.9.1 to 3.0.0
LX.Test
:
LX UI Test
// repository documentation
Was this content helpful?
โ 0
(0 ratings)
Select Rating:
โ
โ
โ
โ
โ
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
toolbar-demo
?
Download (.md)
# Jetpack compose toolbar actions demo Before Jetpack Compose release we were used to add menu items in Fragments or Activities classes with **xml** files and **onCreateOptionsMenu** methods. The new UI tool is a game changer and via **Scaffold** composable it's easy to add global actions to **TopAppBar**. With global actions I mean items that remains visible for the entire lifecycle of the controller class. When using Jetpack Navigation however there is only one Activity and the NavHost swaps composable destinations on the screen. In this scenario is useful to have a concise way to easily add or remove actions from the ToolBar for each navigation route. This sample project aims to resolve this problem. https://user-images.githubusercontent.com/20385374/171950954-90b2c662-39ed-48ce-9e78-a9d261497d6d.mp4 Define a toolbarController instance (Hoist instance as up as possible) ```kotlin val toolbarController = rememberToolbarController() val screenToolbarActions by remember { derivedStateOf { val route = currentBackStackEntry?.destination?.route ?: "" toolbarController.getToolbarActions(route = route) } } ... Scaffold( topBar = { TopAppBar { ToolbarContent( ... screenAdditionalToolbarActions = screenToolbarActions, navController = navController ) } } ) ... ``` In composable Destination define toolbar items ```kotlin @Composable fun FirstScreen( toolbarController: ToolbarController = rememberToolbarController() ) { toolbarController.SetActions( route = NavGraph.FIRST_SCREEN_ROUTE, actions = listOf(ToolbarAction.OpenSettings { Toast.makeText(context, "Settings Action", Toast.LENGTH_SHORT).show() }) ) } ```