Merge pull request #3832 from element-hq/feature/bma/waitingtoMatch

Disable button during the "verifying" step.
This commit is contained in:
Benoit Marty 2024-11-08 14:07:38 +01:00 committed by GitHub
commit 979c4faafe
16 changed files with 62 additions and 54 deletions

View file

@ -10,9 +10,7 @@ package io.element.android.features.verifysession.impl.incoming
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -35,6 +33,7 @@ import io.element.android.libraries.designsystem.components.PageTitle
import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.InvisibleButton
import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TextButton import io.element.android.libraries.designsystem.theme.components.TextButton
import io.element.android.libraries.designsystem.theme.components.TopAppBar import io.element.android.libraries.designsystem.theme.components.TopAppBar
@ -166,8 +165,7 @@ private fun IncomingVerificationBottomMenu(
enabled = false, enabled = false,
showProgress = true, showProgress = true,
) )
// Placeholder so the 1st button keeps its vertical position InvisibleButton()
Spacer(modifier = Modifier.height(40.dp))
} }
} else { } else {
VerificationBottomMenu { VerificationBottomMenu {
@ -194,8 +192,7 @@ private fun IncomingVerificationBottomMenu(
enabled = false, enabled = false,
showProgress = true, showProgress = true,
) )
// Placeholder so the 1st button keeps its vertical position InvisibleButton()
Spacer(modifier = Modifier.height(40.dp))
} }
} else { } else {
VerificationBottomMenu { VerificationBottomMenu {

View file

@ -12,10 +12,8 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -44,6 +42,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
import io.element.android.libraries.designsystem.theme.components.InvisibleButton
import io.element.android.libraries.designsystem.theme.components.OutlinedButton import io.element.android.libraries.designsystem.theme.components.OutlinedButton
import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TextButton import io.element.android.libraries.designsystem.theme.components.TextButton
@ -282,8 +281,7 @@ private fun VerifySelfSessionBottomMenu(
text = stringResource(CommonStrings.action_start_verification), text = stringResource(CommonStrings.action_start_verification),
onClick = { eventSink(VerifySelfSessionViewEvents.RequestVerification) }, onClick = { eventSink(VerifySelfSessionViewEvents.RequestVerification) },
) )
// Placeholder so the 1st button keeps its vertical position InvisibleButton()
Spacer(modifier = Modifier.height(40.dp))
} }
} }
is Step.Canceled -> { is Step.Canceled -> {
@ -293,8 +291,7 @@ private fun VerifySelfSessionBottomMenu(
text = stringResource(CommonStrings.action_done), text = stringResource(CommonStrings.action_done),
onClick = onCancelClick, onClick = onCancelClick,
) )
// Placeholder so the 1st button keeps its vertical position InvisibleButton()
Spacer(modifier = Modifier.height(40.dp))
} }
} }
is Step.Ready -> { is Step.Ready -> {
@ -320,8 +317,7 @@ private fun VerifySelfSessionBottomMenu(
showProgress = true, showProgress = true,
enabled = false, enabled = false,
) )
// Placeholder so the 1st button keeps its vertical position InvisibleButton()
Spacer(modifier = Modifier.height(40.dp))
} }
} }
is Step.Verifying -> { is Step.Verifying -> {
@ -335,17 +331,22 @@ private fun VerifySelfSessionBottomMenu(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
text = positiveButtonTitle, text = positiveButtonTitle,
showProgress = isVerifying, showProgress = isVerifying,
enabled = !isVerifying,
onClick = { onClick = {
if (!isVerifying) { if (!isVerifying) {
eventSink(VerifySelfSessionViewEvents.ConfirmVerification) eventSink(VerifySelfSessionViewEvents.ConfirmVerification)
} }
}, },
) )
TextButton( if (isVerifying) {
modifier = Modifier.fillMaxWidth(), InvisibleButton()
text = stringResource(R.string.screen_session_verification_they_dont_match), } else {
onClick = { eventSink(VerifySelfSessionViewEvents.DeclineVerification) }, TextButton(
) modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.screen_session_verification_they_dont_match),
onClick = { eventSink(VerifySelfSessionViewEvents.DeclineVerification) },
)
}
} }
} }
is Step.Completed -> { is Step.Completed -> {
@ -355,8 +356,7 @@ private fun VerifySelfSessionBottomMenu(
text = stringResource(CommonStrings.action_continue), text = stringResource(CommonStrings.action_continue),
onClick = onContinueClick, onClick = onContinueClick,
) )
// Placeholder so the 1st button keeps its vertical position InvisibleButton()
Spacer(modifier = Modifier.height(48.dp))
} }
} }
is Step.Skipped -> return is Step.Skipped -> return

View file

@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
@ -118,6 +119,14 @@ fun TextButton(
leadingIcon = leadingIcon leadingIcon = leadingIcon
) )
@Composable
fun InvisibleButton(
modifier: Modifier = Modifier,
size: ButtonSize = ButtonSize.Large,
) {
Spacer(modifier = modifier.height(size.toMinHeight()))
}
@Composable @Composable
private fun ButtonInternal( private fun ButtonInternal(
text: String, text: String,
@ -131,14 +140,7 @@ private fun ButtonInternal(
showProgress: Boolean = false, showProgress: Boolean = false,
leadingIcon: IconSource? = null, leadingIcon: IconSource? = null,
) { ) {
val minHeight = when (size) { val minHeight = size.toMinHeight()
ButtonSize.Small -> 32.dp
ButtonSize.Medium,
ButtonSize.MediumLowPadding -> 40.dp
ButtonSize.Large,
ButtonSize.LargeLowPadding -> 48.dp
}
val hasStartDrawable = showProgress || leadingIcon != null val hasStartDrawable = showProgress || leadingIcon != null
val contentPadding = when (size) { val contentPadding = when (size) {
@ -253,6 +255,14 @@ private fun ButtonInternal(
} }
} }
private fun ButtonSize.toMinHeight() = when (this) {
ButtonSize.Small -> 32.dp
ButtonSize.Medium,
ButtonSize.MediumLowPadding -> 40.dp
ButtonSize.Large,
ButtonSize.LargeLowPadding -> 48.dp
}
@Immutable @Immutable
sealed interface IconSource { sealed interface IconSource {
val contentDescription: String? val contentDescription: String?

View file

@ -32,9 +32,10 @@ class KonsistComposableTest {
.withoutReceiverType() .withoutReceiverType()
.withoutName( .withoutName(
// Add some exceptions... // Add some exceptions...
"InvisibleButton",
"OutlinedButton", "OutlinedButton",
"TextButton",
"SimpleAlertDialogContent", "SimpleAlertDialogContent",
"TextButton",
) )
.assertTrue( .assertTrue(
additionalMessage = additionalMessage =

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:dbf6f78ad928bcc9878e546345a98d334ae92c9b81d4d8404892a16d19b446c3 oid sha256:bea78fb1bb813bedce30e5b13257892bcc23a7d6eb1a404d24e764337568d6cd
size 41534 size 41596

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:dfc69dc6d93a62e23df2f817ad5a167b1e94d7fb0d408d6ec0051d666b6cf175 oid sha256:5d8163be5e84aa851df9666822a4d9bc7a40d3a99d6fa8498243c256b729d58f
size 44869 size 44724

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:b76212b5942484621b7a58044a958203d838807d50687e8f4e2f9c8bdb6ad37c oid sha256:db8b048d11f766a8e3db28bac99f3e8dea34e6f37fba1eacd9e6f98f6127462b
size 40232 size 40383

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:1033af0fc84e2819509fc798c17e8f0b07d74a08da99d0e059b7ff19db2ce56a oid sha256:c1098ef994ad9552aca2f9ad9efe7b1239133544e561e73eced6fa96d08eaa3b
size 43674 size 43785

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:18dadaebe7a32aacde31afa0352a343913955b099ca4a07851e3ffe75e88b4d6 oid sha256:104d1d386398aac789420babf33755e03d163f40ae596cd8d24f35da0363fac6
size 31012 size 30952

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:71b9f32b26b391ff3bf231ca9f364a157f535c1e6ff52ee3e3ead3630bb1b239 oid sha256:145c85570217621cc576f305ed72e27205381c438e434205e07b7363cfd67f04
size 30007 size 30069

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:c5435926f4a54e99902b78881c59d9d816110e401bcb92baf3b2fca844338f31 oid sha256:5d8163be5e84aa851df9666822a4d9bc7a40d3a99d6fa8498243c256b729d58f
size 48182 size 44724

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:000374157cb5fbf6670b4af041fc385538df78bf4aecaf83ea24d39dfec84f23 oid sha256:781d869dff205f99d5a9bc9986abbe489bef24551e6fb695280541741895a508
size 24278 size 24238

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4dd274f8c2ade6213a13a47400ec3a571844eafcc82b292b1c813bd9aa098236 oid sha256:85b92d23ab2f690c3c15ded7f14c513371cd36482fbeda1478f62c82650f1829
size 30241 size 30274

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:994b39ba25e011cce97504a1f3d4ed0c420b7bce87daafae77ba481cc629cdae oid sha256:b848d50320f1494c9d0edbc21bddcc773de0cf9b1c36ce034235fd3fbbd77cf1
size 29051 size 29210

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:a6c90e5be60738ded8312822f95279aa76d3ec8d86265164f4e3e31dbcce61c5 oid sha256:c1098ef994ad9552aca2f9ad9efe7b1239133544e561e73eced6fa96d08eaa3b
size 47355 size 43785

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:3a3f08002e805fe5f7a4c96aa4b73c2fcd6e8b79e6a9e82bcc7bd3df50d8c22d oid sha256:5931dfac0337cf856282d9c62983aa185fe208f2926868097238d5b95e222fe6
size 24015 size 23953