Skip to content

Commit

Permalink
Center align on large width.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 27, 2022
1 parent 0a33d48 commit 9ba1161
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import android.view.MenuItem
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
Expand All @@ -20,6 +22,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -55,6 +58,8 @@ class AboutActivity : ComponentActivity() {
}
}

private val defaultSpacerSize = 16.dp

@Composable
fun About(
versionString: String,
Expand Down Expand Up @@ -87,9 +92,22 @@ class AboutActivity : ComponentActivity() {
)
},
content = { scaffoldPadding ->
Box(modifier = Modifier.padding(scaffoldPadding)) {
BoxWithConstraints(
modifier = Modifier
.padding(scaffoldPadding)
.fillMaxWidth()
) {
val scrollAndPadding = Modifier
.verticalScroll(rememberScrollState())
.padding(defaultSpacerSize)
Column(
modifier = Modifier.verticalScroll(rememberScrollState())
modifier = if (maxWidth < 600.dp) {
scrollAndPadding
} else {
scrollAndPadding
.width(600.dp)
.align(Alignment.Center)
}
) {
Text(
text = stringResource(id = R.string.app_name),
Expand Down

0 comments on commit 9ba1161

Please sign in to comment.