-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle buttons toggling in Composer on body draft changes
MAILANDR-2397
- Loading branch information
Showing
5 changed files
with
147 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../main/kotlin/ch/protonmail/android/mailcomposer/presentation/ui/EnabledStateIconButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2022 Proton Technologies AG | ||
* This file is part of Proton Technologies AG and Proton Mail. | ||
* | ||
* Proton Mail is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Proton Mail is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ch.protonmail.android.mailcomposer.presentation.ui | ||
|
||
import androidx.compose.animation.Animatable | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.semantics.disabled | ||
import androidx.compose.ui.semantics.semantics | ||
import ch.protonmail.android.uicomponents.chips.thenIf | ||
import kotlinx.coroutines.launch | ||
import me.proton.core.compose.theme.ProtonTheme | ||
|
||
@Composable | ||
fun EnabledStateIconButton( | ||
icon: Painter, | ||
isEnabled: Boolean, | ||
contentDescription: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
val enabledColor = ProtonTheme.colors.iconNorm | ||
val disabledColor = ProtonTheme.colors.iconDisabled | ||
|
||
val animatedColor = remember { Animatable(if (isEnabled) enabledColor else disabledColor) } | ||
val scope = rememberCoroutineScope() | ||
|
||
LaunchedEffect(isEnabled) { | ||
val targetColor = if (isEnabled) enabledColor else disabledColor | ||
|
||
// Animate to the target color without abrupt interruptions | ||
if (animatedColor.targetValue != targetColor) { | ||
scope.launch { | ||
animatedColor.animateTo( | ||
targetValue = targetColor, | ||
animationSpec = tween(durationMillis = 500) | ||
) | ||
} | ||
} | ||
} | ||
|
||
IconButton( | ||
modifier = modifier | ||
.thenIf(!isEnabled) { semantics { disabled() } }, | ||
onClick = onClick, | ||
enabled = isEnabled | ||
) { | ||
Icon( | ||
painter = icon, | ||
tint = animatedColor.value, | ||
contentDescription = contentDescription | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters