Skip to content

Commit

Permalink
feat: allow closing the drawer using the back button (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeyls authored Mar 2, 2025
1 parent d9b4f65 commit 8f485c3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.androidmakers.ui.common

import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable

@Composable
actual fun BackHandlerCompat(enabled: Boolean, onBack: () -> Unit) {
BackHandler(enabled = enabled, onBack = onBack)
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private fun AgendaFilterDrawerPreview() {
@Composable
private fun AgendaLayoutPreview() {
AgendaLayout(
agendaFilterDrawerState = DrawerState(DrawerValue.Closed, confirmStateChange = { true }),
agendaFilterDrawerState = DrawerState(DrawerValue.Closed),
onSessionClick = { _ -> }
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.androidmakers.ui.common

import androidx.compose.runtime.Composable

@Composable
expect fun BackHandlerCompat(enabled: Boolean = true, onBack: () -> Unit)
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.androidmakers.ui.about.AboutScreen
import com.androidmakers.ui.agenda.AgendaLayout
import com.androidmakers.ui.common.BackHandlerCompat
import com.androidmakers.ui.common.SigninButton
import com.androidmakers.ui.common.SigninCallbacks
import com.androidmakers.ui.speakers.SpeakerScreen
Expand Down Expand Up @@ -120,10 +121,19 @@ fun AVALayout(
actions = {
if (currentRoute == AVANavigationRoute.AGENDA.name) {
val scope = rememberCoroutineScope()
BackHandlerCompat(enabled = agendaFilterDrawerState.isOpen) {
scope.launch {
agendaFilterDrawerState.close()
}
}
IconButton(
onClick = {
scope.launch {
if (agendaFilterDrawerState.isClosed) agendaFilterDrawerState.open() else agendaFilterDrawerState.close()
if (agendaFilterDrawerState.isClosed) {
agendaFilterDrawerState.open()
} else {
agendaFilterDrawerState.close()
}
}
}
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.androidmakers.ui.common

import androidx.compose.runtime.Composable

@Composable
actual fun BackHandlerCompat(enabled: Boolean, onBack: () -> Unit) {
// No-op on iOS
}

0 comments on commit 8f485c3

Please sign in to comment.