Skip to content

Commit

Permalink
fix: clear contact selection instead of closing app when back button …
Browse files Browse the repository at this point in the history
…is pressed
  • Loading branch information
SuhasDissa committed Jan 1, 2024
1 parent 8425a18 commit 5613969
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/com/bnyro/contacts/ui/components/ContactsPage.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bnyro.contacts.ui.components

import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.Crossfade
Expand Down Expand Up @@ -132,8 +133,14 @@ fun ContactsPage(
Column(
modifier = Modifier.padding(pv).fillMaxSize()
) {
Crossfade(targetState = selectedContacts.isEmpty(), label = "main layout") { state ->
when (state) {
Crossfade(
targetState = selectedContacts.isEmpty(),
label = "main layout"
) { selectionEmpty ->
BackHandler(enabled = !selectionEmpty) {
selectedContacts.clear()
}
when (selectionEmpty) {
true -> {
TopAppBar(
title = {
Expand Down Expand Up @@ -240,6 +247,7 @@ fun ContactsPage(
}
)
}

false -> {
TopAppBar(
title = {
Expand Down

0 comments on commit 5613969

Please sign in to comment.