Skip to content

Commit 56f2c46

Browse files
authored
Merge pull request #10015 from rafaeltonholo/chore/9862/add-missing-error-full-screen-dialog-on-compose
feat(in-app-notification): show error notifications in a dialog on compose
2 parents d9fdbef + b84c87c commit 56f2c46

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

feature/notification/api/src/androidMain/kotlin/net/thunderbird/feature/notification/api/ui/InAppNotificationScaffold.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@ package net.thunderbird.feature.notification.api.ui
22

33
import androidx.compose.foundation.layout.PaddingValues
44
import androidx.compose.foundation.layout.consumeWindowInsets
5+
import androidx.compose.foundation.layout.fillMaxSize
56
import androidx.compose.foundation.layout.padding
67
import androidx.compose.foundation.verticalScroll
78
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.getValue
10+
import androidx.compose.runtime.mutableStateOf
11+
import androidx.compose.runtime.remember
12+
import androidx.compose.runtime.setValue
813
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.platform.testTag
15+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
916
import app.k9mail.core.ui.compose.designsystem.organism.snackbar.SnackbarHost
1017
import app.k9mail.core.ui.compose.designsystem.organism.snackbar.SnackbarHostState
1118
import app.k9mail.core.ui.compose.designsystem.organism.snackbar.rememberSnackbarHostState
1219
import app.k9mail.core.ui.compose.designsystem.template.Scaffold
1320
import app.k9mail.core.ui.compose.designsystem.template.ScaffoldFabPosition
1421
import kotlinx.collections.immutable.ImmutableSet
1522
import net.thunderbird.core.ui.compose.common.modifier.testTagAsResourceId
23+
import net.thunderbird.feature.notification.api.ui.InAppNotificationScaffoldDefaults.TEST_TAG_ERROR_NOTIFICATIONS_DIALOG
1624
import net.thunderbird.feature.notification.api.ui.InAppNotificationScaffoldDefaults.TEST_TAG_INNER_SCAFFOLD
1725
import net.thunderbird.feature.notification.api.ui.InAppNotificationScaffoldDefaults.TEST_TAG_IN_APP_NOTIFICATION_HOST
1826
import net.thunderbird.feature.notification.api.ui.InAppNotificationScaffoldDefaults.TEST_TAG_SNACKBAR_HOST
1927
import net.thunderbird.feature.notification.api.ui.action.NotificationAction
28+
import net.thunderbird.feature.notification.api.ui.dialog.ErrorNotificationsDialog
2029
import net.thunderbird.feature.notification.api.ui.host.DisplayInAppNotificationFlag
2130
import net.thunderbird.feature.notification.api.ui.host.rememberInAppNotificationHostStateHolder
2231
import net.thunderbird.feature.notification.api.ui.host.visual.SnackbarVisual
@@ -55,6 +64,7 @@ fun InAppNotificationScaffold(
5564
content: @Composable (PaddingValues) -> Unit,
5665
) {
5766
val hostStateHolder = rememberInAppNotificationHostStateHolder(enabled)
67+
var showErrorNotificationDialog by remember { mutableStateOf(false) }
5868
Scaffold(
5969
modifier = modifier.testTagAsResourceId(TEST_TAG_INNER_SCAFFOLD),
6070
topBar = topBar,
@@ -69,7 +79,12 @@ fun InAppNotificationScaffold(
6979
floatingActionButtonPosition = floatingActionButtonPosition,
7080
) { paddingValues ->
7181
InAppNotificationHost(
72-
onActionClick = onNotificationActionClick,
82+
onActionClick = { action ->
83+
when (action) {
84+
NotificationAction.OpenNotificationCentre -> showErrorNotificationDialog = true
85+
else -> onNotificationActionClick(action)
86+
}
87+
},
7388
contentPadding = paddingValues,
7489
hostStateHolder = hostStateHolder,
7590
onSnackbarNotificationEvent = { visual: SnackbarVisual ->
@@ -86,11 +101,24 @@ fun InAppNotificationScaffold(
86101
modifier = Modifier.testTagAsResourceId(TEST_TAG_IN_APP_NOTIFICATION_HOST),
87102
content = content,
88103
)
104+
105+
if (showErrorNotificationDialog) {
106+
val state by hostStateHolder.currentInAppNotificationHostState.collectAsStateWithLifecycle()
107+
ErrorNotificationsDialog(
108+
visuals = state.bannerInlineVisuals,
109+
onDismiss = { showErrorNotificationDialog = false },
110+
onNotificationActionClick = onNotificationActionClick,
111+
modifier = Modifier
112+
.fillMaxSize()
113+
.testTag(TEST_TAG_ERROR_NOTIFICATIONS_DIALOG),
114+
)
115+
}
89116
}
90117
}
91118

92-
object InAppNotificationScaffoldDefaults {
119+
internal object InAppNotificationScaffoldDefaults {
93120
internal const val TEST_TAG_INNER_SCAFFOLD = "ins_inner_scaffold"
94121
internal const val TEST_TAG_IN_APP_NOTIFICATION_HOST = "ins_in_app_notification_host"
95122
internal const val TEST_TAG_SNACKBAR_HOST = "ins_snackbar_host"
123+
internal const val TEST_TAG_ERROR_NOTIFICATIONS_DIALOG = "ins_error_notifications_dialog"
96124
}

feature/notification/api/src/androidUnitTest/kotlin/net/thunderbird/feature/notification/api/ui/InAppNotificationScaffoldTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import app.k9mail.core.ui.compose.theme2.MainTheme
3939
import assertk.assertThat
4040
import assertk.assertions.isEqualTo
4141
import assertk.assertions.isNotNull
42+
import assertk.assertions.isNull
4243
import kotlin.test.Test
4344
import kotlinx.collections.immutable.persistentSetOf
4445
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -597,13 +598,16 @@ class InAppNotificationScaffoldTest : ComposeTest() {
597598
assertBannerInlineList(size = 2)
598599

599600
// Act (Phase 2)
601+
mainClock.autoAdvance = true
600602
onNodeWithTag(BannerInlineNotificationListHostDefaults.TEST_TAG_CHECK_ERROR_NOTIFICATIONS_ACTION)
601603
.performClick()
602604

603605
// Assert (Phase 2)
604606
assertThat(clickedAction.value)
605-
.isNotNull()
606-
.isEqualTo(NotificationAction.OpenNotificationCentre)
607+
.isNull()
608+
609+
onNodeWithTag(InAppNotificationScaffoldDefaults.TEST_TAG_ERROR_NOTIFICATIONS_DIALOG)
610+
.assertIsDisplayed()
607611
}
608612
// endregion [ Banner Inline List Notification verification ]
609613

0 commit comments

Comments
 (0)