Skip to content

Commit 8b21efa

Browse files
committed
Ensure the invisible buttons have the correct size.
1 parent 700d4c6 commit 8b21efa

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
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: 6 additions & 12 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 -> {
@@ -343,8 +339,7 @@ private fun VerifySelfSessionBottomMenu(
343339
},
344340
)
345341
if (isVerifying) {
346-
// Placeholder so the 1st button keeps its vertical position
347-
Spacer(modifier = Modifier.height(40.dp))
342+
InvisibleButton()
348343
} else {
349344
TextButton(
350345
modifier = Modifier.fillMaxWidth(),
@@ -361,8 +356,7 @@ private fun VerifySelfSessionBottomMenu(
361356
text = stringResource(CommonStrings.action_continue),
362357
onClick = onContinueClick,
363358
)
364-
// Placeholder so the 1st button keeps its vertical position
365-
Spacer(modifier = Modifier.height(48.dp))
359+
InvisibleButton()
366360
}
367361
}
368362
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?

0 commit comments

Comments
 (0)