https://kotlinlang.org
Join Slack
How to scroll to a specific item of a lazy column? I am creating a lazy column based on my model whi...
m

Michael Paus

over 2 years ago
How to scroll to a specific item of a lazy column? I am creating a lazy column based on my model which describes a hierarchical structure with one selected item. (Think of a large book with thousands of pages subdivided into sections and sub-sections.) The column only unfolds and shows the elements which lead to the selected page. So far this is working nicely but then scrolling to the selected item seems to be strange. 1. How do you get at the index of an arbitrary item to be able to scroll to it? Is the below code the proposed way to get at it? 2. Where do you best place the below code (if it is correct) so that it is always executed after the composition because the index is only reliably available after it. 3. What rules does the
animateScrollToItem
follow? It does not seem to scroll the item to the top if this would result in blank space at the bottom of the column.
val index = listState.layoutInfo.visibleItemsInfo.filter {
    it.key == myModelState.selectedReference?.refId }.firstOrNull()?.index
index?.let { listState.animateScrollToItem(index = it) }
All examples I have seen so far only seem to handle the trivial case that you want to scroll to the first item which is simply not a realistic use-case for me.
☝️ 1
➕ 1
m
a
  • 2
  • 4
  • 4596
Is it possible in Jetpack compose to allow a child composable to be bigger than it’s parent, just no...
p

Per Jansson

about 2 years ago
Is it possible in Jetpack compose to allow a child composable to be bigger than it’s parent, just not show the overflowing part and still let the parent composable decide how much is shown? In this example, would it be possible for the inner blue box to actually render as 400dp but that the outer yellow box would not display the overflowing 200dp? Like in the web world with CSS you can use
overflow: hidden | clip
to achieve the same. In the example below both boxes will log that they are 200 in size, I would like the blue one to be 400 but only the top 200 would be visible.
Box(
  modifier = Modifier
    .size(200.dp)
    .background(Color.Yellow)
    .onGloballyPositioned { coordinates ->
       Log.d("BoxSize", "OUTER Width: ${coordinates.size.width}, Height: ${coordinates.size.height}")
    }
) {
    Box(
      modifier = Modifier
        .fillMaxWidth()
        .height(400.dp)
        .background(Color.Blue)
        .onGloballyPositioned { coordinates ->
           Log.d("BoxSize", "INNER Width: ${coordinates.size.width}, Height: ${coordinates.size.height}")
        }
    )
}
➕ 2
p
z
+2
  • 4
  • 7
  • 4572
How can I remove this padding from the Outlined Text Field that is reserved to the label if I dont w...
a

André Thiele

about 4 years ago
How can I remove this padding from the Outlined Text Field that is reserved to the label if I dont want to show a label? Or should I wrap it and clip its contents?
a
c
n
  • 3
  • 13
  • 4210
hello guys, is anyone having this Issue? ```java.lang.IllegalAccessError: class org.jetbrains.kotlin...
m

magnumrocha

almost 4 years ago
hello guys, is anyone having this Issue?
java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x50148e28) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x50148e28
I am having this after update gradle to version 7.2…
youtrack 1
m
z
p
  • 3
  • 18
  • 4196
Is anyone here familiar with the Open Telemetry Kotlin implementation: <https://github.com/open-tele...
j

james

about 3 years ago
Is anyone here familiar with the Open Telemetry Kotlin implementation: https://github.com/open-telemetry/opentelemetry-java/tree/main/extensions/kotlin. I'm trying to find the bit that allows the Span to propogate context across coroutines from a non-suspendable function:
runBlocking {
        val error = IllegalAccessException("Bad things are happening!")
        val message = "Isn't it a nice day"
        Span.current()?.let { span ->
            val attributes = Attributes.builder().apply {
                message?.let { put("error_message", it) }
            }
                .build()

            span.setStatus(StatusCode.ERROR)
            span.recordException(throwable, attributes)
        }
        
        launch { 
            // This will cause the spans to get linked together and then sync metadata from the above. 
            @WithSpan
            suspendFunction()
        }
    }
The reason i'm asking is that i'm trying to understand some strange behavior in our system where the context doesn't always propagate from a parent to child correctly.
j
e
+2
  • 4
  • 10
  • 4043
When is the `init { }` block in a ViewModel called? The init block for Screen A's ViewModel doesn't ...
v

v79

over 2 years ago
When is the
init { }
block in a ViewModel called? The init block for Screen A's ViewModel doesn't seem to be triggered when swiping back from Screen B, for instance.
v
y
+3
  • 5
  • 26
  • 3971
I want to achieve a “dynamic” height LazyVerticalGrid meaning the height of one item in the row dete...
i

iroyo

over 2 years ago
I want to achieve a “dynamic” height LazyVerticalGrid meaning the height of one item in the row determines the height of the rest to avoid the effect of the image. The only “clean” way is to ditch the Grid and make a LazyColumn with a Row as each item?!! I know the other option would be to hard code the same height for every item in the grid, but that would produce (maybe) an unwanted space between rows. The code to produce the example is simple but it’s added in the thread
❤️ 1
i
r
  • 2
  • 10
  • 3919
Hi! How can I detect if Composable element is visible on the screen or vice versa, without too much ...
v

Valentin Gusselnikov

about 3 years ago
Hi! How can I detect if Composable element is visible on the screen or vice versa, without too much calculations? I want to hide the top
Image
if the
Button
(which is placed at the end) is not visible and user have to scroll for it. Root Composable is
ConstraintLayout
🙏 1
v
  • 1
  • 1
  • 3913
What's the correct way of rendering html string in compose? Something very similar to `HtmlCompat.fr...
r

ritesh

over 3 years ago
What's the correct way of rendering html string in compose? Something very similar to
HtmlCompat.fromHtml()
in textView.
👀 1
r
s
z
  • 3
  • 9
  • 3864
I need to render Markdown in Compose (on Android). Does anyone have any recommendation for a library...
m

Marcin Wisniowski

over 2 years ago
I need to render Markdown in Compose (on Android). Does anyone have any recommendation for a library or solution? I'm currently considering this library: https://github.com/jeziellago/compose-markdown Or using this JetBrains library for parsing the Markdown: https://github.com/JetBrains/markdown and writing the Compose code myself to render the parsed text. Does anyone have any insight?
m
o
+4
  • 6
  • 14
  • 3840
Previous123Next

kotlinlang

A modern programming language that makes developers happier.

Powered by