Rafs
03/21/2022, 12:15 PMcreateAndroidComposeRule
doesn't allow calling setContent
anymore if the root content of the Activity has already been set. I remember this used to work in compose beta versions but it's now throwing an IllegalStateException
. I found it to be a really handy way in compose UI testing. Is there any reason why the behaviour was changed?myanmarking
03/21/2022, 12:51 PMdimsuz
03/21/2022, 1:35 PMcomposable("/my/route") {
val value = remember { HeavyValue() }
MyScreen(value)
}
Whenever I navigate back and then forward to this screen, I'd like HeavyValue
to be recreated. In code above it is created once and persists:
push/pop/push <-- will get the same valuemarios proto
03/21/2022, 1:42 PMOutlinedButton(
onClick = actionClick,
enabled = enabled,
colors = buttonColors,
modifier = modifier
.border(
border = BorderStroke(
width = 1.dp,
color = if (enabled) borderColor else disabledColor
),
shape = RoundedCornerShape(4.dp),
)
) {
Text(
text = actionText.uppercase(),
textAlign = TextAlign.Center,
style = CompanyTheme.typography.body,
maxLines = 1,
modifier = Modifier.semantics {
contentDescription = actionContentDescription
}
)
}
Aditya Murthy
03/21/2022, 1:43 PMMichal Klimczak
03/21/2022, 1:47 PMdecorationBox
and showing / hiding the texfield itself when its focus / value changes. There is an issue that when it hides, there is an exception. I guess we should not completely get rid of the inner text field in this scenario, rather hide it - so a simple if
and AnimatedVisibility
will not work here. What I'm looking for is something like the old View.GONE
. Or just a possibility to go from wrapContent to 0 height and vice versa. Any hints how to best achieve it?iamthevoid
03/21/2022, 2:01 PMTgo1014
03/21/2022, 3:23 PMAlejandro Moya
03/21/2022, 4:14 PMSimon Stahl
03/21/2022, 6:47 PMChris Johnson
03/21/2022, 8:30 PManimateContentSize
with say an alpha animation? If not, what's the way we should go about this? Say I want to update the alpha alongside the size change for a Text
. Currently it animates the size first and doesn't appear to get any alpha updates. Code in 🧵james
03/21/2022, 9:31 PMRow
containing just a TextField
and a Button
, what's the proper way to set the TextField's height to always match the Button height? I thought giving the TextField this modifier would do the trick, but it doesn't.. the TextField is still much taller than my button: Modifier.height(IntrinsicSize.Min)
colintheshots
03/21/2022, 9:55 PMMehmet Peker
03/21/2022, 10:00 PMI have an application written with Jetpack Compose in the Google Play Store. I have a custom dialog inside the application. I did not come across it, but my users are getting an IlegalArgumentException error when using Image. Why am I getting this error?
java.lang.IllegalArgumentException:
at androidx.compose.ui.res.PainterResources_androidKt.loadImageBitmapResource (PainterResources_android.kt)
at androidx.compose.ui.res.PainterResources_androidKt.painterResource (PainterResources_android.kt)
Android75
03/22/2022, 7:52 AMSlackbot
03/22/2022, 8:25 AMKareem Waleed
03/22/2022, 9:03 AMDecorView
, but now using compose there's only one view added to the activity's DecorView
which is a ComposeView
that contains no details about the composables dawn inside. Any ideas ?Tgo1014
03/22/2022, 9:41 AMFAB
component, but a custom one because I want to transform it into a bottom sheetBenjamin Deroche
03/22/2022, 9:53 AMBox(
modifier = Modifier.fillMaxSize()
) {
val infiniteTransition: InfiniteTransition = rememberInfiniteTransition()
val initialSize: Float = 72f
val pulsingSize: Float = 88f
val size: Float by infiniteTransition.animateFloat(
initialValue = initialSize,
targetValue = pulsingSize,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 1000,
easing = LinearEasing
),
repeatMode = RepeatMode.Reverse
)
)
val paddingReduction: Float = (size - initialSize) / 2
FloatingActionButton(
modifier = Modifier
.align(Alignment.BottomCenter)
.padding((16f - paddingReduction).dp)
.size(size.dp),
onClick = {}
) {
Icon(
imageVector = Icons.Default.ArrowUpward,
contentDescription = "To the top!"
)
}
}
Vladas
03/22/2022, 11:13 AMMutableState
• var value by remember { mutableStateOf(default) }
• val (value, setValue) = remember { mutableStateOf(default) }
Bad one. In this one composable recomposes every time counter is updated (each second)
@Composable
fun App() {
val (counter, setCounter) = remember { mutableStateOf(1) }
LaunchedEffect(null) {
var i = 1
while (true) {
delay(1000)
setCounter(++i)
}
}
println("recomposition")
val str by remember { derivedStateOf { (counter % 10 == 0).toString() } }
Text(str)
}
This one works properly. Recomposes only when needed str changes. (every 10 seconds two times)
@Composable
fun App() {
var counter by remember { mutableStateOf(1) }
LaunchedEffect(null) {
var i = 1
while (true) {
delay(1000)
counter = ++i
}
}
println("recomposition")
val str by remember { derivedStateOf { (counter % 10 == 0).toString() } }
Text(str)
}
Same behavior using android and js.nuhkoca
03/22/2022, 11:48 AMBrush.linearGradient(
0.5f to Color(0xFF26313C).copy(alpha = .0f),
1.0f to Color(0xFF26313C).copy(alpha = .6f)
)
julioromano
03/22/2022, 2:27 PMLayout()
composable is there a way to somehow group the `measurables`/`placeables` by some property of my data model?
I’m trying to create a custom layout composable which places its children according to some property of the data model from which the children themselves are created.
But from within the Layout()
block the children are exposed as `measurable`/`placeable` so there is no visibility into their props.
Is there a way to pass any property from my data model or from the child composables into their respective measurables/placeables? Or any other way to achieve this (e.g. meta-data or anything else)?Jakub Ledwon
03/22/2022, 3:17 PMBox
but I wonder if there is something just for this use caseTgo1014
03/22/2022, 3:18 PMwrapContentWidth()
to fillMaxWidth()
without using animateContentSize()
? When I use this modifier it clips the elevation shadow 😕Ravi
03/22/2022, 4:18 PMrelease
variant after upgrading constraintlayout(compose) to 1.0.0, it’s working fine in 1.0.0-rc01
. Please let me know if any proguard rules to be added to avoid this crash, more in 🧵nuhkoca
03/22/2022, 4:20 PMCard
, there is being a darker image on the rounded corners on the light mode. Is this a known bug?
Card(
modifier = modifier,
shape = RoundedCornerShape(3.dp),
border = BorderStroke(1.dp, MyTheme.colors.appBackground3)
) {
...
}
andrew
03/22/2022, 4:31 PMMichal Klimczak
03/22/2022, 4:42 PMDmitry Strekha
03/22/2022, 5:10 PMItemDecoration#getItemOffsets
I tried Modifier#offset
, but seems it affects only the item on which the modifier was applied, so items below do not shiftGuilherme Almeida
03/22/2022, 5:36 PMLazyColumn
with mostly TextFields
inside I noticed they were all recomposing on every key stroke for any of the fields.
So if I type in something in the first field, the other fields, even though they did not change their value, will also recompose. After experimenting a bit I pinned it down to using the onFocusChanged
modifier for these text fields. After removing the onFocusChanged
modifier the text fields seem to skip composition. Is this the expected behaviour ?
Quick repro (I am using the the recomposeHighlighter to visualize recompositions):
val state = remember {
List(20) { it to "" }.toMutableStateMap()
}
LazyColumn(Modifier.fillMaxSize()) {
itemsIndexed(state.values.toList()) { index, string ->
TextField(
value = string,
onValueChange = { state[index] = it },
modifier = Modifier
.recomposeHighlighter()
.onFocusChanged { }
)
}
}
Guilherme Almeida
03/22/2022, 5:36 PMLazyColumn
with mostly TextFields
inside I noticed they were all recomposing on every key stroke for any of the fields.
So if I type in something in the first field, the other fields, even though they did not change their value, will also recompose. After experimenting a bit I pinned it down to using the onFocusChanged
modifier for these text fields. After removing the onFocusChanged
modifier the text fields seem to skip composition. Is this the expected behaviour ?
Quick repro (I am using the the recomposeHighlighter to visualize recompositions):
val state = remember {
List(20) { it to "" }.toMutableStateMap()
}
LazyColumn(Modifier.fillMaxSize()) {
itemsIndexed(state.values.toList()) { index, string ->
TextField(
value = string,
onValueChange = { state[index] = it },
modifier = Modifier
.recomposeHighlighter()
.onFocusChanged { }
)
}
}
myanmarking
03/22/2022, 7:46 PMGuilherme Almeida
03/22/2022, 8:29 PMmyanmarking
03/22/2022, 8:48 PMPaul Woitaschek
03/22/2022, 8:53 PMGuilherme Almeida
03/22/2022, 9:02 PMmyanmarking
03/22/2022, 9:06 PMGuilherme Almeida
03/22/2022, 9:06 PMmyanmarking
03/22/2022, 9:09 PMGuilherme Almeida
03/23/2022, 12:12 PMonFocusChanged
modifier is created, so If the modifier is created in the main composable it recomposes for every new state there, if it is inside its own composable then it only recomposes when the state has changed.
Wrapping the modifier with remember
also works, but does not seem ideal