Skip to content

Commit cf9dbc6

Browse files
authored
Merge pull request #3832 from element-hq/feature/bma/waitingtoMatch
Disable button during the "verifying" step.
2 parents a0fb244 + 0dbfab9 commit cf9dbc6

16 files changed

+62
-54
lines changed

features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/incoming/IncomingVerificationView.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ package io.element.android.features.verifysession.impl.incoming
1010
import androidx.activity.compose.BackHandler
1111
import androidx.compose.foundation.layout.Arrangement
1212
import androidx.compose.foundation.layout.Column
13-
import androidx.compose.foundation.layout.Spacer
1413
import androidx.compose.foundation.layout.fillMaxWidth
15-
import androidx.compose.foundation.layout.height
1614
import androidx.compose.foundation.layout.padding
1715
import androidx.compose.material3.ExperimentalMaterial3Api
1816
import androidx.compose.runtime.Composable
@@ -35,6 +33,7 @@ import io.element.android.libraries.designsystem.components.PageTitle
3533
import io.element.android.libraries.designsystem.preview.ElementPreview
3634
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
3735
import io.element.android.libraries.designsystem.theme.components.Button
36+
import io.element.android.libraries.designsystem.theme.components.InvisibleButton
3837
import io.element.android.libraries.designsystem.theme.components.Text
3938
import io.element.android.libraries.designsystem.theme.components.TextButton
4039
import io.element.android.libraries.designsystem.theme.components.TopAppBar
@@ -166,8 +165,7 @@ private fun IncomingVerificationBottomMenu(
166165
enabled = false,
167166
showProgress = true,
168167
)
169-
// Placeholder so the 1st button keeps its vertical position
170-
Spacer(modifier = Modifier.height(40.dp))
168+
InvisibleButton()
171169
}
172170
} else {
173171
VerificationBottomMenu {
@@ -194,8 +192,7 @@ private fun IncomingVerificationBottomMenu(
194192
enabled = false,
195193
showProgress = true,
196194
)
197-
// Placeholder so the 1st button keeps its vertical position
198-
Spacer(modifier = Modifier.height(40.dp))
195+
InvisibleButton()
199196
}
200197
} else {
201198
VerificationBottomMenu {

features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/VerifySelfSessionView.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import androidx.compose.foundation.clickable
1212
import androidx.compose.foundation.layout.Arrangement
1313
import androidx.compose.foundation.layout.Box
1414
import androidx.compose.foundation.layout.Row
15-
import androidx.compose.foundation.layout.Spacer
1615
import androidx.compose.foundation.layout.fillMaxSize
1716
import androidx.compose.foundation.layout.fillMaxWidth
18-
import androidx.compose.foundation.layout.height
1917
import androidx.compose.foundation.layout.padding
2018
import androidx.compose.material3.ExperimentalMaterial3Api
2119
import androidx.compose.runtime.Composable
@@ -44,6 +42,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
4442
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
4543
import io.element.android.libraries.designsystem.theme.components.Button
4644
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
45+
import io.element.android.libraries.designsystem.theme.components.InvisibleButton
4746
import io.element.android.libraries.designsystem.theme.components.OutlinedButton
4847
import io.element.android.libraries.designsystem.theme.components.Text
4948
import io.element.android.libraries.designsystem.theme.components.TextButton
@@ -282,8 +281,7 @@ private fun VerifySelfSessionBottomMenu(
282281
text = stringResource(CommonStrings.action_start_verification),
283282
onClick = { eventSink(VerifySelfSessionViewEvents.RequestVerification) },
284283
)
285-
// Placeholder so the 1st button keeps its vertical position
286-
Spacer(modifier = Modifier.height(40.dp))
284+
InvisibleButton()
287285
}
288286
}
289287
is Step.Canceled -> {
@@ -293,8 +291,7 @@ private fun VerifySelfSessionBottomMenu(
293291
text = stringResource(CommonStrings.action_done),
294292
onClick = onCancelClick,
295293
)
296-
// Placeholder so the 1st button keeps its vertical position
297-
Spacer(modifier = Modifier.height(40.dp))
294+
InvisibleButton()
298295
}
299296
}
300297
is Step.Ready -> {
@@ -320,8 +317,7 @@ private fun VerifySelfSessionBottomMenu(
320317
showProgress = true,
321318
enabled = false,
322319
)
323-
// Placeholder so the 1st button keeps its vertical position
324-
Spacer(modifier = Modifier.height(40.dp))
320+
InvisibleButton()
325321
}
326322
}
327323
is Step.Verifying -> {
@@ -335,17 +331,22 @@ private fun VerifySelfSessionBottomMenu(
335331
modifier = Modifier.fillMaxWidth(),
336332
text = positiveButtonTitle,
337333
showProgress = isVerifying,
334+
enabled = !isVerifying,
338335
onClick = {
339336
if (!isVerifying) {
340337
eventSink(VerifySelfSessionViewEvents.ConfirmVerification)
341338
}
342339
},
343340
)
344-
TextButton(
345-
modifier = Modifier.fillMaxWidth(),
346-
text = stringResource(R.string.screen_session_verification_they_dont_match),
347-
onClick = { eventSink(VerifySelfSessionViewEvents.DeclineVerification) },
348-
)
341+
if (isVerifying) {
342+
InvisibleButton()
343+
} else {
344+
TextButton(
345+
modifier = Modifier.fillMaxWidth(),
346+
text = stringResource(R.string.screen_session_verification_they_dont_match),
347+
onClick = { eventSink(VerifySelfSessionViewEvents.DeclineVerification) },
348+
)
349+
}
349350
}
350351
}
351352
is Step.Completed -> {
@@ -355,8 +356,7 @@ private fun VerifySelfSessionBottomMenu(
355356
text = stringResource(CommonStrings.action_continue),
356357
onClick = onContinueClick,
357358
)
358-
// Placeholder so the 1st button keeps its vertical position
359-
Spacer(modifier = Modifier.height(48.dp))
359+
InvisibleButton()
360360
}
361361
}
362362
is Step.Skipped -> return

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Button.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.PaddingValues
1717
import androidx.compose.foundation.layout.Row
1818
import androidx.compose.foundation.layout.Spacer
1919
import androidx.compose.foundation.layout.fillMaxWidth
20+
import androidx.compose.foundation.layout.height
2021
import androidx.compose.foundation.layout.heightIn
2122
import androidx.compose.foundation.layout.padding
2223
import androidx.compose.foundation.layout.size
@@ -118,6 +119,14 @@ fun TextButton(
118119
leadingIcon = leadingIcon
119120
)
120121

122+
@Composable
123+
fun InvisibleButton(
124+
modifier: Modifier = Modifier,
125+
size: ButtonSize = ButtonSize.Large,
126+
) {
127+
Spacer(modifier = modifier.height(size.toMinHeight()))
128+
}
129+
121130
@Composable
122131
private fun ButtonInternal(
123132
text: String,
@@ -131,14 +140,7 @@ private fun ButtonInternal(
131140
showProgress: Boolean = false,
132141
leadingIcon: IconSource? = null,
133142
) {
134-
val minHeight = when (size) {
135-
ButtonSize.Small -> 32.dp
136-
ButtonSize.Medium,
137-
ButtonSize.MediumLowPadding -> 40.dp
138-
ButtonSize.Large,
139-
ButtonSize.LargeLowPadding -> 48.dp
140-
}
141-
143+
val minHeight = size.toMinHeight()
142144
val hasStartDrawable = showProgress || leadingIcon != null
143145

144146
val contentPadding = when (size) {
@@ -253,6 +255,14 @@ private fun ButtonInternal(
253255
}
254256
}
255257

258+
private fun ButtonSize.toMinHeight() = when (this) {
259+
ButtonSize.Small -> 32.dp
260+
ButtonSize.Medium,
261+
ButtonSize.MediumLowPadding -> 40.dp
262+
ButtonSize.Large,
263+
ButtonSize.LargeLowPadding -> 48.dp
264+
}
265+
256266
@Immutable
257267
sealed interface IconSource {
258268
val contentDescription: String?

tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistComposableTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ class KonsistComposableTest {
3232
.withoutReceiverType()
3333
.withoutName(
3434
// Add some exceptions...
35+
"InvisibleButton",
3536
"OutlinedButton",
36-
"TextButton",
3737
"SimpleAlertDialogContent",
38+
"TextButton",
3839
)
3940
.assertTrue(
4041
additionalMessage =
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)