Piotr Prus
12/13/2021, 7:03 PMNat Strangerweather
12/13/2021, 10:29 PMMiguel Vargas
12/14/2021, 12:00 AMremember
to save the AndroidView as follows but it’s still recreating the Views as I scroll up and down. Is there any way to make it more efficient?
@Composable
fun ViewInLazyColumn() {
LazyColumn {
items(100) { idx ->
val context = LocalContext.current
val view = remember { MyView(context, idx.toString()) }
AndroidView(factory = { view }) } } }
class MyView(context: Context, value: String) : TextView(context) {
init {
// View keeps getting recreated
println("init MyView $value")
text = value } }
Libor Bicanovsky
12/14/2021, 12:35 AMcondition?.let {
//some composable
} ?: //other composable
In 1.1.0-beta04 this will not work correctly and the second condition will never be evaluated/displayed.
It works correctly in previous versions (such as 1.0.5). Just wanted to mention it since it caught us out!mattinger
12/14/2021, 2:23 AMOG
12/14/2021, 6:50 AMTgo1014
12/14/2021, 8:39 AMAnkit Shah
12/14/2021, 11:18 AMBrian G
12/14/2021, 3:08 PMPHondogo
12/14/2021, 3:25 PMjava.lang.NoSuchMethodError: No static method infiniteRepeatable-9IiC70o$default(Landroidx/compose/animation/core/DurationBasedAnimationSpec;Landroidx/compose/animation/core/RepeatMode;JILjava/lang/Object;)Landroidx/compose/animation/core/InfiniteRepeatableSpec; in class Landroidx/compose/animation/core/AnimationSpecKt; or its super classes (declaration of 'androidx.compose.animation.core.AnimationSpecKt'
mattinger
12/14/2021, 5:07 PMBrian Donovan
12/14/2021, 5:10 PMLucien Guimaraes
12/14/2021, 6:52 PM<string name="news_count_title">{{count}} {{text}}</string>
. I would like count
and text
to have different styles. How to properly achieve it in Compose?Colton Idle
12/14/2021, 9:01 PMText
?
I clicked into a Text and I see
fontSize: TextUnit = TextUnit.Unspecified,
Colton Idle
12/14/2021, 9:13 PMBox(
modifier.fillMaxWidth().graphicsLayer {
scaleY = 1000f
clip = false
},
Is there a way to prevent this clipping? I thought compose didn't clip by default? Even if it did, I thought clipToBounds() would allow me to pass in "false" but it does not.jeff
12/14/2021, 10:43 PMclass Helper {
val string = "string"
}
@Composable
fun RecompRepro(mutableState: MutableState<String>, helper: Helper) {
LogCompositions(msg = "Root")
Column(Modifier.height(100.dp)) {
Text(mutableState.value)
CustomComposableText(helper = helper)
}
}
@Composable
fun CustomComposableText(helper: Helper) {
LogCompositions(msg = "CustomComposableText")
Text(helper.string)
}
if I change the value of mutableState 3 times, "Root" is printed 3 times and "CustomComposableText" is printed 1 time. That is as expected.
But if I change val string
to var string
in Helper
, then all of a sudden CustomComposableText is printed 3 times. Why?bbade_
12/15/2021, 12:20 AMColumn
Button1
*OddUi*
Button3
Lets say i wanted to override primary
and onPrimary
when rendering the OddUi content.
What’s the best way of doing this?
MaterialTheme’s colors are mutableStateOf
, so do i write
Button1()
MaterialTheme.primary = somethingElse
MaterialTheme.Colors.onPrimary = somethingElse
OddUi()
// restore the two colors
Button2
This feels odd
or would i write
Button1()
CompositionLocalProvider(LocalColors provides MaterialTheme.colors.copy(primary = ..., onPrimary = ...) {
OddUi()
}
Button2
With this though, localColors is internal, so i can’t override it, right?
Is there a third option?Colton Idle
12/15/2021, 3:05 AMval successEvent = {
scope.launch {
bottomSheetState.hide()
}
}
This works greats except that if the user happens to be touching the bottom sheet while I call hide(), then it won't actually hide. Is there another way to force the sheet to hide if I really need it to hide, or am I out of luck/file a feature request?nilTheDev
12/15/2021, 6:43 AMboxes
- nested in rows
and columns
- with some border around them. However, in some of the boxes
the border appears to be thicker than others. Anybody knows why this is happening? In the code, the thickness of the border of all the boxes
are same.PHondogo
12/15/2021, 7:06 AMjava.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/animation/core/StartOffset;
when calling
InfiniteRepeatableSpec(
animation = tween(200, easing = LinearEasing),
repeatMode = RepeatMode.Restart,
initialStartOffset = StartOffset(0)
)
?jean
12/15/2021, 9:11 AM"io.coil-kt:coil-compose:1.4.0"
instead of accompanist
and I’m back at the same problem. Images are not loading when I set them from the items
block of the LazyListScope
block. Do I need to change anything?
Image(
painter = rememberImagePainter(url),
contentDescription = stringResource(id = R.string.description),
contentScale = ContentScale.Crop,
modifier = Modifier
.width(150.dp)
.height(267.dp),
)
Guilherme Delgado
12/15/2021, 10:39 AMinputs.forEach {
TextFieldWrapper(
id = ...,
text = ...,
onTextChanged = { my callback implementation }
)
...
}
More in thread.loloof64
12/15/2021, 10:53 AMloloof64
12/15/2021, 11:02 AMprintln()
call from an interactive @Preview
in Android Studio ?Hachemi Hamadi
12/15/2021, 11:30 AME/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cardshop.app.compose, PID: 12745
java.lang.IllegalStateException: measure() may not be called multiple times on the same Measurable
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:86)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:71)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1293)
at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasurePolicy$1.measure-3p2s80s(RowColumnImpl.kt:89)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:51)
at androidx.compose.foundation.ScrollingLayoutModifier.measure-3p2s80s(Scroll.kt:342)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:39)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:306)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:39)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:131)
at androidx.compose.foundation.layout.PaddingModifier.measure-3p2s80s(Padding.kt:364)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:39)
at androidx.compose.foundation.layout.FillModifier.measure-3p2s80s(Size.kt:658)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:39)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:100)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:99)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:126)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:88)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:76)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:99)
at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1302)
at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release$default(LayoutNode.kt:1298)
at androidx.compose.ui.node.LayoutNode.onBeforeLayoutChildren(LayoutNode.kt:1080)
at androidx.compose.ui.node.LayoutNode.layoutChildren$ui_release(LayoutNode.kt:961)
at androidx.compose.ui.node.LayoutNode.onNodePlaced$ui_release(LayoutNode.kt:954)
at androidx.compose.ui.node.InnerPlaceable.placeAt-f8xVGno(InnerPlaceable.kt:125)
at androidx.compose.ui.layout.Placeable.access$placeAt-f8xVGno(Placeable.kt:31)
at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50(Placeable.kt:370)
at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50$default(Placeable.kt:203)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper$measure$1$1.placeChildren(DelegatingLayoutNodeWrapper.kt:138)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.placeAt-f8xVGno(DelegatingLayoutNodeWrapper.kt:126)
at androidx.compose.ui.layout.Placeable.access$placeAt-f8xVGno(Placeable.kt:31)
at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50(Placeable.kt:370)
loloof64
12/15/2021, 12:09 PMclass
and String
? Or is even this last very bad practice ?Colton Idle
12/15/2021, 3:14 PMtrevjones
12/15/2021, 3:35 PMEspresso.setFailureHandler { error, viewMatcher ->
val scan = Radiography.scan(viewStateRenderers = DefaultsIncludingPii)
error.addSuppressed(RuntimeException("\n$scan"))
error.addSuppressed(RuntimeException(idlingRegistryStatus))
DefaultFailureHandler(targetContext).handle(error, viewMatcher)
}
Is there a good way to do similar with the compose rule + testing apis?Javier
12/15/2021, 3:44 PMBilly Newman
12/15/2021, 3:54 PMBilly Newman
12/15/2021, 3:54 PM@Composable
fun Content(someComposable: (@Composable () -> Unit)? = null) {
val background = someComposable?.background() // This does not work
}
Kirill Grouchnikov
12/15/2021, 4:14 PMsomeComposable
is not a view / container / component in the traditional sense. It may emit one UI component, it may emit more than one, or it may not emit anything.Billy Newman
12/15/2021, 4:17 PMinterface CustomScope {
@Stable
fun Modifier.background(background: Color): Modifier
}
@Composable
fun Content(someComposable: (@Composable CustomScope.() -> Unit)? = null) {
...
}
Adam Powell
12/15/2021, 4:19 PMBilly Newman
12/15/2021, 4:43 PM@Composable
fun CommonContent(header: (@Composable () -> Unit)? = null) {
DragHandle()
header?.invoke()
}
@Composable
fun CustomContent() {
CommonContent() {
// custom header
Column(Modifier.background(Color.Blue)) { ... }
}
}
I would like for the drag handle view to have the same background color as the custom header. And I don’t really want to duplicate code. IE in this case a drag handle is “common” and should always be present regardless of the custom header.Casey Brooks
12/15/2021, 4:57 PMCommonContent
, you can use CompositionLocals to implicitly pass parameters down through the composition tree https://developer.android.com/jetpack/compose/compositionlocalChris Sinco [G]
12/15/2021, 5:04 PMMaterialTheme
like MaterialTheme.colors.background
can be useful here because from the code POV you are using a semantic color key, but can use CompositionLocal to override in specific parts in the hierarchy if needed.Billy Newman
12/15/2021, 5:11 PM@Composable
fun CommonContent(
header: (@Composable () -> Unit)? = null,
headerColor: Color = Color.White
) {
DragHandle(headerColor)
header?.invoke()
}
But where does that end. Passing in every attribute the drag handle would have in common with the header component seems excessive.interface ParentDataModifier : Modifier.Element {
/**
* Provides a parentData, given the [parentData] already provided through the modifier's chain.
*/
fun Density.modifyParentData(parentData: Any?): Any?
}
To allow the child to modify something on the parent right? Seems like exactly what I am trying to do.Chris Sinco [G]
12/15/2021, 5:17 PMNot really sure I want to pass parameters “down”Right, this is where CompositionLocals can be useful as it passes things down in the hierarchy, and it works particularly well for color overrides at certain parts of a UI hierarchy
Casey Brooks
12/15/2021, 5:20 PMval LocalHeaderColor = compositionLocalOf { Color.Unspecified }
@Composable
fun CommonContent(
header: (@Composable () -> Unit)? = null,
headerColor: Color = Color.White
) {
CompositionLocalProvider(LocalHeaderColor provides headerColor) {
DragHandle()
header?.invoke()
}
}
The content of both DragHandle
and the header
lambda can then reference the configured header color with LocalHeaderColor.current
, without having to pass it explicitly through function parametersBilly Newman
12/15/2021, 6:32 PMChris Sinco [G]
12/15/2021, 6:38 PMAdam Powell
12/15/2021, 6:45 PM