JsonTree icon indicating copy to clipboard operation
JsonTree copied to clipboard

Unmeasured height in scrollable parent

Open ehsannarmani opened this issue 1 year ago • 3 comments

Hi, dear. First of anything, thank you for publishing this usefull library.

I was using the json tree in a scrollable parent, but it seems you are using fillMaxHeight in a part of your code which causes unmeasured height crash (infinity height), becuase of that, i should set height for the json tree or max height. The suggestion is if you can, depend the json tree height on content.

ehsannarmani avatar Jul 27 '24 13:07 ehsannarmani

Hi, thank you for using JsonTree!

JsonTree adapts to the height of its content, but it uses a LazyColumn internally to render the tree, which can cause a crash when the parent is also scrollable. You can prevent that by applying a fixed height or weight to JsonTrees Modifier, depending on your layout. Something like this could work:

Column(
    modifier = Modifier
        .fillMaxSize()
        .verticalScroll(rememberScrollState())
) {
    // some content

    JsonTree(
       modifier = Modifier
            .height(500.dp) // or weight(1F)
            .fillMaxWidth()
    )

    // some content
}

snappdevelopment avatar Jul 28 '24 07:07 snappdevelopment

Right, using weight not working, i should give fixed height or heightIn(2000.dp) to make it height depend on it content.

ehsannarmani avatar Jul 28 '24 08:07 ehsannarmani

You can give JsonTree any fixed height that you want, since JsonTree itself is scrollable. So you can choose how much space it should take in your scrollable parent. I think heightIn() will still crash for the same reason.

snappdevelopment avatar Jul 28 '24 14:07 snappdevelopment