• m

    Mohammad Sianaki

    11 months ago
    Hi. I’m trying to implement a collapsing toolbar but my code is so laggy, and it causes recomposition of screen body while scrolling screen.
    @Composable
    fun Demo() {
        val scroll = rememberScrollState(0)
        Column(modifier = Modifier.fillMaxSize()) {
            CollapsingToolbar(scroll = scroll.value, title = "Screen Title")
            Body(scroll)
        }
    }
    
    
    @Composable
    fun Body(scroll: ScrollState) {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .verticalScroll(scroll)
        ) {
            repeat(5) {
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .height(200.dp)
                        .background(Color.Red)
                )
            }
        }
    }
    
    @Composable
    fun CollapsingToolbar(
        scroll: Int,
        title: String,
        onNavigateUpClicked: () -> Unit = {},
    ) {
        val collapseRange = with(LocalDensity.current) {
            (150.dp - 56.dp).toPx()
        }
        val collapseFraction = (scroll / collapseRange).coerceIn(0f, 1f)
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .heightIn(min = 56.dp)
                .wrapContentHeight()
                .background(Color.Green),
        ) {
            IconButton(
                onClick = onNavigateUpClicked,
                modifier = Modifier
                    .padding(start = 8.dp, top = 8.dp)
                    .background(Color.Cyan)
                    .align(Alignment.TopStart)
    
            ) {
                Icon(
                    imageVector = Icons.Default.ArrowBack,
                    contentDescription = null,
                    modifier = Modifier.background(Color.Red)
                )
            }
            Text(
                text = title,
                style = MaterialTheme.typography.h6,
                modifier = Modifier
                    .padding(start = 24.dp, top = 150.dp * (1 - collapseFraction))
                    .align(Alignment.CenterStart)
                    .offset(x = 32.dp * collapseFraction)
            )
        }
    }
    m
    Jan Bína
    +1
    3 replies
    Copy to Clipboard
  • e

    eygraber

    11 months ago
    Did the getValue/
    setValue
    import issue ever get resolved? I thought I saw that it was a while ago, but I'm re-exploring Compose and I'm running into issues with it not getting imported.
    e
    1 replies
    Copy to Clipboard
  • Nikhil

    Nikhil

    11 months ago
    Is there a way to preserve the drawing buffer/frame in canvas? If i’m using
    LaunchedEffect(){…}
    along with
    withFrameNanos{..}
    to update a state (using loop, say for creating a game or animation). Can the previous frame be preserved without recomposition in jetpack compose? Something like
    preserveDrawingBuffer
    in JS.
    Nikhil
    Zach Klippenstein (he/him) [MOD]
    4 replies
    Copy to Clipboard
  • e

    elye

    11 months ago
    Hi here… I’m trying out hybrid of RecyclerView and ComposeViewHolder.. but looks like everytime it binds, it
    setContent
    , cause to it be slower. The profile looks as the image below. How can it be speed up? FYI, the detail question in.https://stackoverflow.com/questions/69514265/how-to-make-recyclerview-with-composable-viewholder-render-faster
    e
    adjpd
    +3
    7 replies
    Copy to Clipboard
  • a

    alorma

    11 months ago
    Alert dialogs with lists looks... weird
    a
    Albert Chang
    3 replies
    Copy to Clipboard
  • Csaba Szugyiczki

    Csaba Szugyiczki

    11 months ago
    [ScrollView fillViewport] There were a few discussions about how to replicate ScrollView-s fillViewport=true behaviour. The same can be definitely achieved with a Column having
    fillMaxHeight
    height, and then applying the
    verticalScroll
    modifier on it. But if we use an inner Column, then the way it is measured is different than what we got used to using XML layouts. Setting an inner Columns height to
    wrapContentHeight
    and applying
    .weight(1f)
    on it only respects the weight modifier, but the
    wrapContentHeight
    modifier is ignored. This makes the
    Column
    cut its children. Is there a workaround for this? Sample code in 🧵
    Csaba Szugyiczki
    Albert Chang
    9 replies
    Copy to Clipboard
  • Matti MK

    Matti MK

    11 months ago
    Are there any sample projects available where Kotlin Flow, without LiveData, is used with Compose?
    Matti MK
    Csaba Kozák
    3 replies
    Copy to Clipboard
  • m

    Michael Ndiritu

    11 months ago
    Hello, in compose how can we prevent the app from switching to dark mode when system goes to dark mode
    m
    Csaba Kozák
    2 replies
    Copy to Clipboard
  • Zoltan Demant

    Zoltan Demant

    11 months ago
    Is it possible to specify that a text should use the condensed style, similar to how you might specify its font-weight; or do I need to specify a completely different TextStyle which points to the condensed variant?
    Zoltan Demant
    Albert Chang
    8 replies
    Copy to Clipboard
  • Zoltan Demant

    Zoltan Demant

    11 months ago
    Is it possible to specify a LazyList to be the size of its largest child? When using a LazyRow with different item heights, the height is always that of the largest currently visible item - scrolling past a large item will jump the entire UI due to the LazyLists height being reduced.
    Zoltan Demant
    Csaba Szugyiczki
    +1
    5 replies
    Copy to Clipboard