Close navigation drawer on back press
Some checks are pending
Build & Test / Validate (pull_request) Successful in 22s
Build & Test / Run Unit Tests (pull_request) Successful in 8m20s
Build & Test / Run UI Tests (pull_request) Successful in 12m23s
Build & Test / Validate (push) Waiting to run
Build & Test / Run Unit Tests (push) Blocked by required conditions
Build & Test / Run UI Tests (push) Blocked by required conditions

This commit is contained in:
William Brawner 2024-08-21 22:20:25 -06:00
parent 90ab7f9397
commit 094ac1fccf

View file

@ -1,5 +1,6 @@
package com.wbrawner.simplemarkdown.ui package com.wbrawner.simplemarkdown.ui
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
@ -29,6 +30,11 @@ fun MarkdownNavigationDrawer(
) { ) {
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
BackHandler(enabled = drawerState.isOpen) {
coroutineScope.launch {
drawerState.close()
}
}
DismissibleNavigationDrawer( DismissibleNavigationDrawer(
gesturesEnabled = drawerState.isOpen, gesturesEnabled = drawerState.isOpen,
drawerState = drawerState, drawerState = drawerState,