Skip to content

Commit

Permalink
Ensure the invisible buttons have the correct size.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Nov 7, 2024
1 parent 700d4c6 commit 8b21efa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ package io.element.android.features.verifysession.impl.incoming
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
Expand All @@ -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.PreviewsDayNight
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.TextButton
import io.element.android.libraries.designsystem.theme.components.TopAppBar
Expand Down Expand Up @@ -166,8 +165,7 @@ private fun IncomingVerificationBottomMenu(
enabled = false,
showProgress = true,
)
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(40.dp))
InvisibleButton()
}
} else {
VerificationBottomMenu {
Expand All @@ -194,8 +192,7 @@ private fun IncomingVerificationBottomMenu(
enabled = false,
showProgress = true,
)
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(40.dp))
InvisibleButton()
}
} else {
VerificationBottomMenu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -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.theme.components.Button
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.Text
import io.element.android.libraries.designsystem.theme.components.TextButton
Expand Down Expand Up @@ -282,8 +281,7 @@ private fun VerifySelfSessionBottomMenu(
text = stringResource(CommonStrings.action_start_verification),
onClick = { eventSink(VerifySelfSessionViewEvents.RequestVerification) },
)
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(40.dp))
InvisibleButton()
}
}
is Step.Canceled -> {
Expand All @@ -293,8 +291,7 @@ private fun VerifySelfSessionBottomMenu(
text = stringResource(CommonStrings.action_done),
onClick = onCancelClick,
)
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(40.dp))
InvisibleButton()
}
}
is Step.Ready -> {
Expand All @@ -320,8 +317,7 @@ private fun VerifySelfSessionBottomMenu(
showProgress = true,
enabled = false,
)
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(40.dp))
InvisibleButton()
}
}
is Step.Verifying -> {
Expand All @@ -343,8 +339,7 @@ private fun VerifySelfSessionBottomMenu(
},
)
if (isVerifying) {
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(40.dp))
InvisibleButton()
} else {
TextButton(
modifier = Modifier.fillMaxWidth(),
Expand All @@ -361,8 +356,7 @@ private fun VerifySelfSessionBottomMenu(
text = stringResource(CommonStrings.action_continue),
onClick = onContinueClick,
)
// Placeholder so the 1st button keeps its vertical position
Spacer(modifier = Modifier.height(48.dp))
InvisibleButton()
}
}
is Step.Skipped -> return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand Down Expand Up @@ -118,6 +119,14 @@ fun TextButton(
leadingIcon = leadingIcon
)

@Composable
fun InvisibleButton(
modifier: Modifier = Modifier,
size: ButtonSize = ButtonSize.Large,
) {
Spacer(modifier = modifier.height(size.toMinHeight()))
}

@Composable
private fun ButtonInternal(
text: String,
Expand All @@ -131,14 +140,7 @@ private fun ButtonInternal(
showProgress: Boolean = false,
leadingIcon: IconSource? = null,
) {
val minHeight = when (size) {
ButtonSize.Small -> 32.dp
ButtonSize.Medium,
ButtonSize.MediumLowPadding -> 40.dp
ButtonSize.Large,
ButtonSize.LargeLowPadding -> 48.dp
}

val minHeight = size.toMinHeight()
val hasStartDrawable = showProgress || leadingIcon != null

val contentPadding = when (size) {
Expand Down Expand Up @@ -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
sealed interface IconSource {
val contentDescription: String?
Expand Down

0 comments on commit 8b21efa

Please sign in to comment.