Thread
#compose
    Ioane Sharvadze

    Ioane Sharvadze

    1 year ago
    Is there maximum Width Constraint in Compose? 🤔 I'm getting
    Can't represent a size of 1168750 in Constraints
    Error log when running this code
    @Composable
    fun Calendar() {
        Surface {
            Box(
                modifier = Modifier
                    .padding(10.dp)
                    .size(200.dp)
                    .horizontalScroll(rememberScrollState())
            ) {
                CalendarBox()
            }
        }
    }
    
    @Composable
    fun CalendarBox() {
        Box(modifier = Modifier.width(500_000.dp)) {
            Text(text = "Event 1", modifier = Modifier.offset(x = 50.dp))
            Text(text = "Event 2", modifier = Modifier.offset(x = 499_950.dp))
        }
    }
    
    @Preview
    @Composable
    fun CalendarPreview() {
        Calendar()
    }
    Basically, I want to write the widget that is very very wide. (Like calendar). I had similar code running in
    View-based-approach
    and it worked well. Now I want to translate that into compose based solution And I'm stuck with this issue. If this is framework limitation, is there any suggested approach how can I overcome this? 🤔
    gildor

    gildor

    1 year ago
    I don’t think it’s a good solution to have very wide widget, it should instead use something like lazy column or any other dynamic rendering approach
    it’s also an issue with View, it cannot be too big, it may crash (and it also device specific)
    Ioane Sharvadze

    Ioane Sharvadze

    1 year ago
    Yeah, but I need to use Box, because I do have items which could overlap and with LazyColumn, LazyRow there is no such option. :S
    gildor

    gildor

    1 year ago
    Not necessary LazyColumn, you probably should use canvas instead, or other solution to do that dynamically depending on position
    Ioane Sharvadze

    Ioane Sharvadze

    1 year ago
    Thank you, I will try something 🤔
    I would expect that compose could optimize this somehow. If the view is 1million pixels and viewPort is 10k pixels, it should not draw outside. But logically view can be very large. Like an event that is started at year 2000 and ends at year 2050. Implementing this in canvas would be very, very difficult, since I could not use
    offsets
    and sizing properly :S
    gildor

    gildor

    1 year ago
    It will not optimize it magically
    Using lazy column for calendar looks as natural solution, it's a potentially infinite list, so it's not very scalable to use predefined view for this, if there is no way to implement it with lazy column, then own implementation of it is pretty logical, we do the same with views too now
    Ioane Sharvadze

    Ioane Sharvadze

    1 year ago
    Thank you!