Tolriq
10/07/2021, 7:01 AMcollectAsLazyPagingItems
the state is collected in a launched effect so even if the flow is cached and available if the collect is started in a composable that is recreated there's at least a frame running with no content and the position is reset to 0. In that case I can collect earlier in a scope that is not removed as the data is cached. But what if I wanted to actually not keep the data, reload it then restore scroll. Is there some official doc / pattern for that ?Michael Bichlmeier
10/07/2021, 7:25 AMText
should be from parent.start
until Divider
2. Text and Divider+Icon have to be centered with 5% spacing to start and end
3. Icon has his own click area
I will post an example code snippet in the thread. I’m very interested in your ideas how to do this in a “simple” way 😉Radoslaw Juszczyk
10/07/2021, 7:37 AMslartus
10/07/2021, 8:26 AMritesh
10/07/2021, 8:58 AMHtmlCompat.fromHtml()
in textView.Florian
10/07/2021, 9:23 AMcomposable
path 😣.athos
10/07/2021, 9:30 AMMIN_H
and MAX_H
. If the vertical available space is more than MAX_H
, the column should leave some empty space at the bottom, and if it is less than MIN_H
, the content will be scrollable. I thought I could get this quite easily with Modifier.heightIn()
but it doesn't matter where I put it or what I pass to it I never get the desired result. Example code in the thread.ziv kesten
10/07/2021, 10:39 AMText
implementation that can take SpannedString
?ziv kesten
10/07/2021, 12:27 PMLouis
10/07/2021, 2:06 PMDmitriy Gaiduk
10/07/2021, 2:34 PMval resources = new LokaliseResources(context)
val text = resources.getString(R.string.screen_title)
What’s the best way to store and create the LokaliseResources
object in Compose? We want to use the LokaliseResources.getString ()
function as a replacement for androidx.compose.ui.res.stringResource ()
.
We now have an implementation like this:
@Composable
fun CustomTheme(
useDarkTheme: Boolean = false,
content: @Composable () -> Unit,
) {
val colors = if (useDarkTheme) DarkColorPalette else LightColorPalette
val colorPalette = remember { colors }
colorPalette.update(colors)
MaterialTheme(
colors = debugColors(),
typography = MaterialTypography,
) {
CompositionLocalProvider(
CustomColors provides colorPalette,
content = content,
)
}
}
class Screen : com.bluelinelabs.conductor.Controller {
private val lokaliseResources: LokaliseResources by lazy { LokaliseResources(activity) }
private fun getString(@StringRes resId: Int): String {
return lokaliseResources.getString(resId)
}
@Composable
fun Content() {
CustomTheme(useDarkTheme = false) {
Text(value = getString(R.string.screen_title))
}
}
}
But the problem is that you cannot get a string resource outside of the Screen
class in any Compose method. Is it possible to create LokaliseResources in a singleton? Or can this be added to CustomTheme
somehow?Alexander Suraphel
10/07/2021, 2:40 PMMake sure you're using Kotlin 1.5.21 in your project.
Will Kotlin version 1.5.31
work?Andrew Hughes
10/07/2021, 5:52 PMwrapContentWidth(unbounded = true)
modifier on the Text
composable, however, this has the side-effect of never wrapping the text, which I don't necessarily want. I started looking into creating a transition and using AnimatedContent
but I haven't been having much luck so far.Lilly
10/07/2021, 6:47 PM@Stable
and would expect that a change to the property would reflect the new state but it doesn't:
@Stable
data class StableState(var isChecked: Boolean)
@Composable
fun StableTest(state: StableState) {
Checkbox(checked = state.isChecked, onCheckedChange = {
state.isChecked = it
})
}
What did I miss?Ink
10/07/2021, 8:57 PMbrabo-hi
10/07/2021, 11:22 PMCard
composablesmallshen
10/08/2021, 5:20 AMAlex
10/08/2021, 6:57 AMAndrei Kovalev
10/08/2021, 9:01 AMzIndex
, but the problem is that in lazy LazyGrid Implementation
val rows = (scope.totalSize + nColumns - 1) / nColumns
LazyColumn(
modifier = modifier,
state = state,
contentPadding = contentPadding
) {
items(rows) { rowIndex ->
Row {
for (columnIndex in 0 until nColumns) {
val itemIndex = rowIndex * nColumns + columnIndex
if (itemIndex < scope.totalSize) {
Box(
modifier = Modifier.weight(1f, fill = true),
propagateMinConstraints = true
) {
scope.contentFor(itemIndex, this@items).invoke()
}
} else {
Spacer(Modifier.weight(1f, fill = true))
}
}
}
}
}
our composable items are wrapped in a Box, but zIndex
only works for direct children of the composable node.
How would you resolve this issue? Any suggestions are welcomeLucien Guimaraes
10/08/2021, 10:16 AMAlex
10/08/2021, 10:32 AMLazyRow
items to fill the max available width (and size their children accordingly?)Felipe
10/08/2021, 3:00 PMJeferson Boesing
10/08/2021, 8:00 PMViewModel
that defines a mutableStateOf
property? I found that Snapshot.withMutableSnapshot
or snapshotFlow
can be used to achieve this, has anyone used this strategy?Mehdi Haghgoo
10/08/2021, 8:03 PMadjpd
10/09/2021, 12:04 AMColton Idle
10/09/2021, 1:08 AMSteve C
10/09/2021, 5:10 AMdata class MyBox(val index: Int, val color: Color)
@Composable
fun DraggingTest() {
val boxes = mutableListOf<MyBox>()
boxes.add(MyBox(0, Color.Blue))
boxes.add(MyBox(1, Color.Red))
boxes.add(MyBox(2, Color.Green))
ConstraintLayout(modifier = Modifier
.fillMaxSize()
.background(Brush.verticalGradient(listOf(Color.Black, Color.Transparent)))
) {
if(boxes.isNotEmpty()) {
DraggableBox(index = boxes[0].index, color = boxes[0].color, boxes.takeLast(boxes.size-1))
}
}
}
@Composable
fun DraggableBox(index: Int, color: Color, boxes: List<MyBox>) {
val initialYOffset = if(index == 0) 0f else 100f
Box(modifier = Modifier.fillMaxSize())
{
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(initialYOffset) }
Box(modifier = Modifier
.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.size(150.dp).background(color)
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consumeAllChanges()
offsetX.value = (offsetX.value + dragAmount.x)
offsetY.value = (offsetY.value + dragAmount.y)
}
}
) {
Text("Box $index", modifier = Modifier.align(Alignment.BottomCenter)
.offset(0.dp, 20.dp))
if(boxes.isNotEmpty()) {
DraggableBox(index = boxes[0].index, color = boxes[0].color, boxes.takeLast(boxes.size-1))
}
}
}
}
elye
10/09/2021, 6:03 AMLinearLayout
? (i.e. ConstraintLayout is preferred over LinearLayout). Or
• in JetpackCompose, there’ll be no performance impact using `Column`/`Row`, and the Compose’s ConstraintLayout
is just to make placement easier (for some case), but no performance benefit?
Thanks!Laco
10/09/2021, 7:15 AMpaddingFromBaseline
in Text.
I saw this document and wrote code as below
@Composable
fun TwoTexts(...) {
Row(modifier.height(IntrinscisSize.Min) {
// skipped other modifiers
Text(text = "Hi", modifier = modifier.paddingFromBaseline(top = 26.sp, bottom = 10.sp)
Divider(...)
Text(text = "there", ...)
}
}
// TextSize = 24.sp
// LineHeight = 36.sp
But ui rendered differently.
I think that text measured by paddingFromBaseline
even if it's smaller than Baseline value
Is this the result intended by IntrinsicSize.Min?
Please look at pictures below
Thanks!Marc
10/09/2021, 9:36 AM