From deb6426edffbb1fa2cd7277daa20049b646adad8 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sun, 20 Aug 2023 12:38:10 +0200 Subject: [PATCH] Close Drawer on back pressed --- .../readrops/app/compose/timelime/TimelineTab.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt b/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt index 4f07d3ea..d38fdad8 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt @@ -1,5 +1,6 @@ package com.readrops.app.compose.timelime +import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -64,10 +65,19 @@ object TimelineTab : Tab { val navigator = LocalNavigator.currentOrThrow val scrollState = rememberLazyListState() - val swipeToRefreshState = rememberSwipeRefreshState(isRefreshing) + val swipeState = rememberSwipeRefreshState(isRefreshing) val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val scope = rememberCoroutineScope() + BackHandler( + enabled = drawerState.isOpen, + onBack = { + scope.launch { + drawerState.close() + } + } + ) + ModalNavigationDrawer( drawerState = drawerState, drawerContent = { @@ -119,7 +129,7 @@ object TimelineTab : Tab { }, ) { paddingValues -> SwipeRefresh( - state = swipeToRefreshState, + state = swipeState, onRefresh = { viewModel.refreshTimeline() },