Vinay Gaba
10/22/2020, 3:56 AMSocheat KHAUV
10/22/2020, 7:21 AMConstraintLayout {
val (imageRef: ConstrainedLayoutReference,
text1Ref: ConstrainedLayoutReference,
text2Ref: ConstrainedLayoutReference,
text3Ref: ConstrainedLayoutReference) = createRefs()
Image(
asset = imageResource(id = R.drawable.hq720),
modifier = Modifier.constrainAs(
imageRef
) {
top.linkTo(anchor = parent.top, margin = 0.dp)
start.linkTo(anchor = parent.start, margin = 0.dp)
} then Modifier.preferredWidth(100.dp)
)
Text(
text = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30",
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.subtitle1.copy(fontSize = 12.sp),
color = Color.White,
modifier = Modifier.constrainAs(
text1Ref
) {
start.linkTo(anchor = imageRef.end, margin = 0.dp)
end.linkTo(anchor = parent.end, margin = 0.dp)
top.linkTo(anchor = parent.top, margin = 0.dp)
}
)
Text(
text = "Simply Nailogica!",
style = MaterialTheme.typography.caption.copy(fontSize = 7.sp),
color = Color.White,
modifier = Modifier.constrainAs(
text2Ref
) {
start.linkTo(anchor = imageRef.end, margin = 0.dp)
end.linkTo(anchor = parent.end, margin = 0.dp)
top.linkTo(anchor = text1Ref.bottom, margin = 0.dp)
}
)
Text(
text = "2 views 31/08/2020 * Stream",
style = MaterialTheme.typography.caption.copy(fontSize = 6.sp),
color = Color.White,
modifier = Modifier.constrainAs(
text3Ref
) {
start.linkTo(imageRef.end)
end.linkTo(parent.end)
bottom.linkTo(imageRef.bottom)
}
)
}
Socheat KHAUV
10/22/2020, 7:51 AMText(
maxLines = 2,
overflow = TextOverflow.Ellipsis,
text = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30", style = TextStyle(
fontFamily = FontFamily.Serif,
fontWeight =
FontWeight.W900,
fontSize = 14.sp,
)
then the title text will look become weird, I am not sure it is constraint layout bug or I missed out something.Halil Ozercan
10/22/2020, 8:23 AMDaniele B
10/22/2020, 9:47 AMText
composable seems to only accept sp
font-sizes, and not dp
.
There are some situations, where using sp
(i.e. allowing the system to adjust the text size according to user general settings) is going to break a layout. So you want to couple the text to the layout (e.g. when you want to display a text on just one line, which has a limited width).
On the traditional Android view system, it was possible to use dp
instead of sp
for text.
How can I deal with this in JetpackCompose ?William Barbosa
10/22/2020, 11:24 AMChethan
10/22/2020, 11:46 AMimport androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.Text
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.ripple.RippleIndication
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.ui.tooling.preview.Preview
@Preview
@Composable
fun Preview() {
ScrollableColumn(modifier = Modifier.fillMaxWidth().background(Color.DarkGray)) {
(1..10).forEach {
Button(50.dp, 16)
}
var text = remember { mutableStateOf("") }
OutlinedTextField(
value = text.value,
keyboardType = KeyboardType.Text,
onValueChange = { text.value = it },
)
}
}
@Composable
fun Button(buttonSize: Dp, fontSize: Int) {
Row(
modifier = Modifier.wrapContentWidth().wrapContentHeight().padding(top = 10.dp),
verticalAlignment = Alignment.CenterVertically
) {
val toggleIndex = remember { mutableStateOf(0) }
(1..5).forEach { index ->
val isSelected = toggleIndex.value == index
Box(
modifier = Modifier
.border(
1.dp,
color = if (isSelected) Color.Black else Color.White,
CircleShape
)
.background(
color = if (isSelected) Color.Black else Color.White,
shape = CircleShape
)
.selectable(
enabled = true,
selected = true,
onClick = { toggleIndex.value = index },
indication = RippleIndication(bounded = true, radius = 24.dp)
).preferredSize(buttonSize)
) {
Text(
text = index.toString(),
style = TextStyle(
color = if (isSelected) Color.White else Color.Black,
fontSize = fontSize.sp,
textAlign = TextAlign.Center
),
modifier = Modifier.align(Alignment.Center)
)
}
Spacer(modifier = Modifier.width(10.dp))
}
}
}
József Szilvási
10/22/2020, 12:13 PMDaniele B
10/22/2020, 12:23 PMval typography = Typography(
body1 = TextStyle(
fontWeight = FontWeight.Normal,
fontSize = 20.sp,
letterSpacing = 0.5.sp
)
)
If I change the fontsize on my own typography, it also seems to affect Texts where I specify a MaterialTheme
style
Text(text = row.nome, style = MaterialTheme.typography.body1, fontWeight = FontWeight.Bold)
I was expecting it would only affect Text where my own typography is specified:
Text(text = row.nome, style = typography.body1, fontWeight = FontWeight.Bold)
How is it supposed to work?Dylan
10/22/2020, 12:27 PMGrigorii Yurkov
10/22/2020, 12:54 PMalorma
10/22/2020, 2:01 PMjaqxues
10/22/2020, 2:37 PMGrigorii Yurkov
10/22/2020, 3:02 PMonResume()
and what I supposed to do now.P.J.
10/22/2020, 3:44 PMstartDestination
when the main activity is launched from a notification and was destroyed before? onNewIntent()
isn't called and the navigation graph doesn't exist yet. Appreciate any ideas.mattinger
10/22/2020, 4:10 PMJeisson Sáchica
10/22/2020, 5:40 PM@Stable
val EmptyRectangleShape: Shape = object: Shape {
override fun createOutline(size: Size, density: Density): Outline =
Outline.Rectangle(Rect.Zero)
}
Alexander Sitnikov
10/22/2020, 5:53 PMlike this▾
Modifier.drawLayer(rotationY = someValue)
, but this animation looks too distorted (like this▾
setCameraDistance()
method, and RenderNode has this method too, but Compose doesn't use any of them. It seems to me that rotationY
parameter is kinda useless without camera distance. Is there any way to create this card flip animation other than drawLayer
? Or maybe there's plans to include support for camera distance in future versions of Compose?Grigorii Yurkov
10/22/2020, 7:21 PMLiveData<T>.observeAsState()
function. Where is it located?P.J.
10/22/2020, 7:53 PMjava.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/runtime/savedinstancestate/RestorableStateHolderKt;
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:104)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:58)
Currently getting this on latest snapshot build when NavHost()
is called, was trying out deep links/args with compose navigation. Anyone else or is this on my end? Edit: Seems to be happening when going from build 6921995 to 6922573Grigorii Yurkov
10/22/2020, 8:49 PM@Composable
fun Test() {
var checked by remember { mutableStateOf(isMyServiceRunning()) }
if (checked) {
startMyService()
} else {
stopMyService()
}
Switch(checked = checked, onCheckedChange = { checked = it})
// ... A lot of others composable functions
}
As far as I understand, one switch will cause recomposition of entire Test()
function, won't it?alorma
10/23/2020, 9:16 AMMayank Saini
10/23/2020, 9:28 AMText
marquee? Any ideas?Irving
10/23/2020, 9:43 AManimatedValue
animation.I could start the animate
animation by supply a different target
.And I also try it for animatedValue
or animatedFloat
but it doesn't work.jaqxues
10/23/2020, 5:16 PMEmphasisLevel.Low
? The difference and contrast between High and Medium is pretty stark if you want to fine tune the Emphasis. So why not simply add a Low
when there is High
and Medium
?Luke
10/23/2020, 5:49 PMFloatingActionButton
over a LazyColumnFor
and I’m trying to add bottom padding on the content of the column so the last element is not hidden by the FAB, like this:
LazyColumnFor(
items = itemList,
contentPadding = PaddingValues(bottom = 88.dp),
...
) { ... }
It works almost perfectly, but the items appear in the padding suddenly as they reach the column content frame. I would prefer them being drawn even if they are only visible in the padding. I guess I’m looking for an equivalent to android:clipToPadding="false"
. Any tips?Grigorii Yurkov
10/23/2020, 6:31 PM@Preview
@Composable
fun MyToolbar() {
Text(
text = "My Toolbar",
fontWeight = FontWeight.Bold,
fontSize = 20.sp,
modifier = Modifier.background(MaterialTheme.colors.primary).height(56.dp).fillMaxWidth(),
textAlign = TextAlign.Left,
color = Color.White
)
}
I decided to use Text
, but it doesn't want to align leftGabriel
10/23/2020, 7:09 PMDaniels Šatcs
10/23/2020, 9:44 PM@Composable
fun drawer() {
val scrollState = rememberScrollState()
Scaffold(
drawerContent = {},
) {
ScrollableColumn(scrollState = scrollState) {
1.until(1000).forEach {
Text(modifier = Modifier.padding(8.dp).fillMaxWidth(), text = it.toString())
}
}
}
}
For some reason scrolling the list right after the drawer is closed does not seem to work. Waiting half a second before scrolling works, but that's not how a user would expect it to behave.
My guess is that the drawer's scrim is blocking the touch events from coming through. Is this a known issue or is this in any way the intended behavior? Attaching a videoGuy Bieber
10/23/2020, 9:54 PM