Skip to content

Commit

Permalink
Create enabledAndNotLoading state and don't set enabled in parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagar0-0 committed Jan 8, 2025
1 parent d95a002 commit 0d6ee32
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core-ui/src/main/java/org/signal/core/ui/Rows.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -108,26 +109,30 @@ object Rows {
label: String? = null,
textColor: Color = MaterialTheme.colorScheme.onSurface,
isLoading: Boolean = false,
enabled: Boolean = !isLoading
enabled: Boolean = true
) {
val enabledAndNotLoading by rememberSaveable(isLoading,enabled) {
mutableStateOf(!isLoading && enabled)
}

Row(
modifier = modifier
.fillMaxWidth()
.clickable(enabled = enabled) { onCheckChanged(!checked) }
.clickable(enabled = enabledAndNotLoading) { onCheckChanged(!checked) }
.padding(defaultPadding()),
verticalAlignment = CenterVertically
) {
TextAndLabel(
text = text,
label = label,
textColor = textColor,
enabled = enabled,
enabled = enabledAndNotLoading,
modifier = Modifier.padding(end = 16.dp)
)

val loadingContent by rememberDelayedState(isLoading)
val toggleState = remember(checked, loadingContent, enabled, onCheckChanged) {
ToggleState(checked, loadingContent, enabled, onCheckChanged)
val toggleState = remember(checked, loadingContent, enabledAndNotLoading, onCheckChanged) {
ToggleState(checked, loadingContent, enabledAndNotLoading, onCheckChanged)
}

AnimatedContent(
Expand Down

0 comments on commit 0d6ee32

Please sign in to comment.