https://kotlinlang.org logo
#compose
Title
# compose
i

Ioane Sharvadze

06/25/2021, 8:52 AM
Is there maximum Width Constraint in Compose? 🤔 I'm getting
Copy code
Can't represent a size of 1168750 in Constraints
Error log when running this code
Copy 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? 🤔
g

gildor

06/25/2021, 9:09 AM
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)
i

Ioane Sharvadze

06/25/2021, 9:34 AM
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
g

gildor

06/25/2021, 9:35 AM
Not necessary LazyColumn, you probably should use canvas instead, or other solution to do that dynamically depending on position
i

Ioane Sharvadze

06/25/2021, 9:46 AM
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
g

gildor

06/25/2021, 12:04 PM
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
👍 2
i

Ioane Sharvadze

06/27/2021, 1:31 PM
Thank you!
4 Views