• Mayank Saini

    Mayank Saini

    1 year ago
    I have recently upgraded to compose
    alpha08
    I have encountered this error in
    layout
    while measuring height.
    java.lang.IllegalArgumentException: maxHeight(-35) must be >= minHeight(0)
    This is the code snippet.
    SubcomposeLayout(modifier = modifier) { constraints ->
            val layoutWidth = constraints.maxWidth
            val layoutHeight = constraints.maxHeight
            val gridTopOffset = 10.dp.toPx().toInt()
            val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0)
            layout(width = layoutWidth, height = layoutHeight) {
                val imagePlaceables = subcompose(GamesCompositionContent.Image, image).fastMap {
                    it.measure(looseConstraints.copy(minHeight = layoutHeight))
                }
                val imageWidth = imagePlaceables.fastMaxBy { it.width }?.width ?: 0
    
                val gridPlaceables = subcompose(GamesCompositionContent.GamesGrid) {
                    val innerPadding = PaddingValues(
                        start = if (imageWidth != 0) (imageWidth / 2).toDp() else 0.dp
                    )
                    grid(innerPadding)
                }.fastMap {
                    it.measure(
                        looseConstraints.copy(
                            maxWidth = layoutWidth - imageWidth / 2,
                            maxHeight = layoutHeight - gridTopOffset
                        )
                    )
                }
    The code was working perfectly and no crashes on
    alpha07
    .
    Mayank Saini
    jim
    +1
    4 replies
    Copy to Clipboard
  • d

    darkmoon_uk

    1 year ago
    Anyone else think Google's Jetpack Compose API reference is just awful? It has all the Jetpack packages combined into a single space, so that you can't easily separate one (i.e. Compose) from any other. Search that doesn't indicate which package/library a result is from, and parts of compose split across packages in a way that makes it hard to locate anything - useless... the JetPack Playground documentation is unofficial, possibly out of date, but does a far better job of being usable.
    d
    Timo Drick
    +2
    6 replies
    Copy to Clipboard
  • a

    allan.conda

    1 year ago
    Is there available API currently which logs node interactions with compose? for debugging purposes?
    a
    Zach Klippenstein (he/him) [MOD]
    8 replies
    Copy to Clipboard
  • Nat Strangerweather

    Nat Strangerweather

    1 year ago
    ```
    I don't understand why the animation works when I select the button but not when I deselect it. Any ideas? Here is my code. Also, are there any animation effects, like bouncing etc out of the box, or do they have to be implemented from scratch?
    ```var isSelected = selectedIndex.value == index
    val scale = animate(if (isSelected) 1f else 0f)
    
                if (color != null) {
                    Column(
                        Modifier.fillMaxWidth(), horizontalAlignment = CenterHorizontally,
                        verticalArrangement = Arrangement.Center
                    ) {
                        Box(Modifier.fillMaxWidth(), Center) {
                            Card(
                                backgroundColor = color,
                                modifier = Modifier.size(100.dp)
                                    .padding(10.dp)
                                    .clip(CircleShape)
                                    .clickable(
                                        indication = null,
                                        onClick = {
                                            selectedIndex.value = index
                                            isSelected = !isSelected
                                        }
                                    )
                            ) {
                                Box(Modifier.fillMaxSize(), Center) {
                                    when (index) {
                                        0 -> Icon(alarm)
                                        1 -> Icon(mediaSounds)
                                        2 -> Icon(touchSounds)
                                        3 -> Icon(Icons.Rounded.Notifications)
                                        4 -> Icon(events)
                                        5 -> Icon(Icons.Rounded.Email)
                                    }
                                }
                            }
                            Box(Modifier.fillMaxSize(), Center) {
                                OptionsPopUp(scale = scale, color = color)
                            }
                        }
                        Text(text = string, style = typography.subtitle2)
                    }
                }
            }
        }
    }
    Nat Strangerweather
    Doris Liu
    4 replies
    Copy to Clipboard
  • k

    Kshitij Patil

    1 year ago
    With these ~40 lines of code, I was able to build a fully functioning
    AutoCompleteTextFIeld
    . Power of Jetpack Compose 🔥
    @Composable
    fun AutoCompleteTextField(
        initialText: String,
        itemList: List<String>,
        onQuery: (String) -> Unit,
        onClearResults: () -> Unit,
        modifier: Modifier = Modifier
    ) {
        val (field, changeField) = savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue(text = initialText) }
        LaunchedEffect(subject = field.text) {
            if (!field.text.isBlank()) {
                delay(1000L)
                onQuery(field.text.trim())
            }
        }
        LazyColumn(modifier = modifier.animateContentSize()) {
            item { 
                TextField(
                    value = field,
                    onValueChange = {
                        changeField(it)
                        onClearResults()
                    },
                    maxLines = 1
                ) 
            }
            if (itemList.isNotEmpty() && !field.isBlank()) {
                items(itemList) { item ->
                    Text(
                        item,
                        modifier = Modifier
                            .padding(4.dp)
                            .clickable(onClick = {
                                changeField(TextFieldValue(item))
                            })
                    )
                }
            }
        }
    }
    You can find a gist here for future reference: https://gist.github.com/Kshitij09/01ed382d395273dd0eac453003265ad9 Any suggestion are welcome 🙂 One issue I found was with the cursor offsets. I need some way to move the cursor to the end on selecting an item from suggestion-list. I tried to do something with
    OffsetMap
    but didn't work.
    k
    c
    +1
    6 replies
    Copy to Clipboard
  • c

    Charles Burton

    1 year ago
    So, I’m new to Jetpack and I’m having what are admittedly some problems related to my newness. For reference I’m using the version shipped with the current canary build of Android Studio and I’m running Ubuntu 20.04.1 as my dev machine. The device I’m working with is a Pixel 4a 5G fully up to date. 1. I can’t seem to get reload to work. In the sample app created by default when I change the text “Android” to “World” no combination of rebuild and send preview to device seems to update the text. 2. Dark mode colors seem to not work, all I have is black text on a blacker background. I’ve tried adjusting the colors but the same problem as above seems to make reloading them not function.
    c
    Alejandro Rios
    +1
    6 replies
    Copy to Clipboard
  • z

    zsperske

    1 year ago
    do Columns/LazyColumns have any diffing functionality if you replace an element or elements in the middle of the list or will it recompose the whole list?
    z
    1 replies
    Copy to Clipboard
  • b

    Bradleycorn

    1 year ago
    Is there a Codelab or Tutorial or Blog Series or anything from the Google team regarding animations in Compose?
    b
    1 replies
    Copy to Clipboard
  • Shakil Karim

    Shakil Karim

    1 year ago
    Anyone else having issues with performance on some devices while using Compose? is it a known issue, And Does it will get better on beta or stable release?
    Shakil Karim
    1 replies
    Copy to Clipboard
  • s

    Sam

    1 year ago
    Does anyone have experience with the new suspend scrolling functions added in
    alpha08
    , specifically
    lazyListState.smoothScrollBy
    and
    lazyListState.snapToItemIndex
    ? We have a chat application so these new functions are critical for starting at the bottom of the message list, as well as revealing new messages into view as they arrive. However, the api is quite cumbersome for these reasons: •
    snapToItemIndex
    takes an index, but it’s not very easy to know how many items are in a
    LazyColumn
    , because there could be group headers, arbitrary items etc and
    firstVisibleItemIndex
    doesn’t help much •
    snapToItemIndex
    will only align the item to the top of the LazyColumn’s viewport, which is unhelpful in scenarios of scrolling to the very bottom of the list. There’s also
    scrollOffset
    param but this requires every [variable height] item to be measured to calculate the offset, is this even possible? •
    smoothScrollBy
    seems to only take a relative offset, as you can imagine if 3 new messages come in within a chat interface, it’s a tough time to calculate everything needed to scroll to bottom, including the height of all new items as well as the current scroll position. I know some might suggest using
    reverseScrollDirection
    to avoid some of these challenges, but that leads to a bunch of tradeoffs down the line (e.g. maintaining scroll position when user is scrolled up, control over animation of new messages, infinite scroll older msgs, etc). Plus it’s not even available yet on
    LazyColumn
    !
    s
    Andrey Kulikov
    +1
    4 replies
    Copy to Clipboard