diff options
| author | David Göransson <david.goransson@mullvad.net> | 2025-07-15 10:31:30 +0200 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2025-07-17 11:17:09 +0200 |
| commit | 00bba9cdbdfcb7719b1e89ede22d30896bd827df (patch) | |
| tree | 7025723afdb1b7a853a063a64c9d056a721202b6 /android/lib/ui | |
| parent | 176f0a8569e6c0d99d0ff5b79d88a69ad1183880 (diff) | |
| download | mullvadvpn-00bba9cdbdfcb7719b1e89ede22d30896bd827df.tar.xz mullvadvpn-00bba9cdbdfcb7719b1e89ede22d30896bd827df.zip | |
Fix focus on notification close
Diffstat (limited to 'android/lib/ui')
| -rw-r--r-- | android/lib/ui/component/src/main/kotlin/net/mullvad/mullvadvpn/lib/ui/component/AnimatedNotificationBanner.kt | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/android/lib/ui/component/src/main/kotlin/net/mullvad/mullvadvpn/lib/ui/component/AnimatedNotificationBanner.kt b/android/lib/ui/component/src/main/kotlin/net/mullvad/mullvadvpn/lib/ui/component/AnimatedNotificationBanner.kt index 4a9bdf1769..8889a37399 100644 --- a/android/lib/ui/component/src/main/kotlin/net/mullvad/mullvadvpn/lib/ui/component/AnimatedNotificationBanner.kt +++ b/android/lib/ui/component/src/main/kotlin/net/mullvad/mullvadvpn/lib/ui/component/AnimatedNotificationBanner.kt @@ -16,8 +16,13 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.testTag @@ -41,6 +46,7 @@ fun AnimatedNotificationBanner( notification: InAppNotification?, isPlayBuild: Boolean, openAppListing: () -> Unit, + contentFocusRequester: FocusRequester, onClickShowAccount: () -> Unit, onClickShowChangelog: () -> Unit, onClickDismissChangelog: () -> Unit, @@ -49,9 +55,20 @@ fun AnimatedNotificationBanner( ) { // Fix for animating to invisible state val previous = rememberPrevious(current = notification, shouldUpdate = { _, _ -> true }) + + val isVisible = notification != null + + val isNotificationDismissed = !isVisible && previous != null + val notificationHasFocus = remember { mutableStateOf(false) } + LaunchedEffect(isNotificationDismissed) { + // If the notification is dismissed, we want to reset the previous notification + if (isNotificationDismissed && notificationHasFocus.value) { + contentFocusRequester.requestFocus() + } + } AnimatedVisibility( - modifier = modifier, - visible = notification != null, + modifier = modifier.onFocusChanged { notificationHasFocus.value = it.hasFocus }, + visible = isVisible, enter = slideInVertically(initialOffsetY = { -it }), exit = slideOutVertically(targetOffsetY = { -it }), ) { |
