Close Drawer on back pressed

This commit is contained in:
Shinokuni 2023-08-20 12:38:10 +02:00
parent 3f665e6ab5
commit deb6426edf
1 changed files with 12 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package com.readrops.app.compose.timelime package com.readrops.app.compose.timelime
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@ -64,10 +65,19 @@ object TimelineTab : Tab {
val navigator = LocalNavigator.currentOrThrow val navigator = LocalNavigator.currentOrThrow
val scrollState = rememberLazyListState() val scrollState = rememberLazyListState()
val swipeToRefreshState = rememberSwipeRefreshState(isRefreshing) val swipeState = rememberSwipeRefreshState(isRefreshing)
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
BackHandler(
enabled = drawerState.isOpen,
onBack = {
scope.launch {
drawerState.close()
}
}
)
ModalNavigationDrawer( ModalNavigationDrawer(
drawerState = drawerState, drawerState = drawerState,
drawerContent = { drawerContent = {
@ -119,7 +129,7 @@ object TimelineTab : Tab {
}, },
) { paddingValues -> ) { paddingValues ->
SwipeRefresh( SwipeRefresh(
state = swipeToRefreshState, state = swipeState,
onRefresh = { onRefresh = {
viewModel.refreshTimeline() viewModel.refreshTimeline()
}, },