Status Update
Comments
gr...@google.com <gr...@google.com>
gr...@google.com <gr...@google.com>
st...@google.com <st...@google.com> #2
I recently put together a demo which centered text in our TitleCard - it should work to provide just the title field if that matches your requirements better (note that I needed to use Modifier.fillMaxWidth() on Text to fill the space):
TitleCard(
onClick = { /* Do something */ },
title = {
Text("Wed, May 8", textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge, modifier = Modifier.fillMaxWidth() )
},
subtitle = {
Text("5:30-6PM at Central Station Restaurant", textAlign = TextAlign.Center)
},
shape = RoundedCornerShape(percent = 50),
content = { Text("Dinner with my agent", textAlign = TextAlign.Center) }
)
Perhaps this is around expectations of Card
, which is a basic component and doesn't apply any formatting or layout (AppCard and TitleCard are built on top of it) - this was the case for Material 2.5 as well. The change in aosp/3103263 to set the minimum height to 64dp was a UX design choice (otherwise, the Card would resemble a Button with min height 52dp).
We could add the ContainerMinHeight token value into the API if there is a need for it, please will you share your code to demonstrate the issue?
to...@gmail.com <to...@gmail.com> #3
The problem is not HorizontalCentering it's vertical.
Even:
TitleCard({}, title = {Text( "ABCD", textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge, modifier = Modifier.fillMaxWidth() )})
Will have the text at the top and a ton of space below the text. If the content does not fit vertically it should be centered, else it looks ugly IMO.
The problem about the tokens is always the same it's all private and we can't use to tweak the design by reusing them.
In this case I can't get the minHeight so can't fake it. If I want to build my own component I can't access the corner value that was changed recently, and so my copy of the component is no more up to date.
The basic card being a basic reusable block, we should be able to center content if needed.
Since the API publicly expose the content as a ColumnScope.()
then the API is explicit that it's a column and so maybe just expose the Column verticalArrangement/horizontalAlignment to give users proper controls?
st...@google.com <st...@google.com> #4
Looking again at this, I don't think the height is actually needed in order to vertically center the content of Card:
Card(
onClick = {},
) {
Column(
modifier = Modifier.fillMaxHeight(), verticalArrangement = Arrangement.Center
) {
Text(
"ABCD",
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge,
modifier = Modifier.fillMaxWidth()
)
}
}
see attachment.
However - we have included Button height as ButtonDefaults.height and it makes sense to be consistent for Card, so we will add it to CardDefaults as well.
to...@gmail.com <to...@gmail.com> #5
Unless it was fixed or updated in M3 cards you can't use fillmaxheight in a container with intrinsic min size and the reason of the first post. So I guess that if it now works the card was changed and this is fixed.
ap...@google.com <ap...@google.com> #6
Branch: androidx-main
commit 7f4323b11a070222301ce583411897cffb877848
Author: stevebower <stevebower@google.com>
Date: Tue Sep 17 15:14:21 2024
Added Shape and Height to CardDefaults
Also added a demo of a base Card with vertically centered content.
Bug: 347649765
Test: Manual testing
Relnote: "We have added CardDefaults.Shape and CardDefaults.Height, which (being tokens) were otherwise private to developers using the library."
Change-Id: I1594a5907bee183eb2183dec2e85e791c6dda3be
M wear/compose/compose-material3/api/current.txt
M wear/compose/compose-material3/api/restricted_current.txt
M wear/compose/compose-material3/integration-tests/src/main/java/androidx/wear/compose/material3/demos/CardDemo.kt
M wear/compose/compose-material3/src/main/java/androidx/wear/compose/material3/Card.kt
st...@google.com <st...@google.com>
pr...@google.com <pr...@google.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.wear.compose:compose-material3:1.0.0-alpha26
Description
Component used: Wear M3 Card Version used: latest master snapshot.
Due tohttps://android-review.googlesource.com/c/platform/frameworks/support/+/3103263 that introduce a minheight but also force an intrinsic min we now have no way to center small text inside the Card.
The normal hack would have been to wrap the internal card content with a box and height Intrinsic.Max but this does not work (Probably due to the forced
.height(IntrinsicSize.Min)
)So we need to wrap in a box with a minheight of the proper height but the token is private so we need to hardcode the 64.dp and if there's some new changes to the design it won't be applied properly on the clients.
The need is simple inside the card show a small text that should be centered and not forced at the top with tons of empty space below.