Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create enabledAndNotLoading state and don't set enabled in parameter #13890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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