orbit-compose icon indicating copy to clipboard operation
orbit-compose copied to clipboard

Make TextField.error/info slots non-nullable

Open hrach opened this issue 2 years ago • 1 comments

Currently, the only solution to this I have is to utilize SubcomposeLayout for rendering, that will make impossible intrinsic measuring on textfield.

But maybe it has its worth. When somebody needs intrinsic measuring, it is quite specific usecase that can be handled without this high-level component.

    SubcomposeLayout { constraints ->
        val errorPlaceable = subcompose("error") {
            error()
        }.firstOrNull()?.measure(constraints)
        val infoPlaceable = subcompose("info") {
            info()
        }.firstOrNull()?.measure(constraints)

        val hasError = errorPlaceable != null && errorPlaceable.height > 0
        val hasInfo = infoPlaceable != null && infoPlaceable.height > 0
        val state = when {
            hasError -> Message.Error(error)
            hasInfo -> Message.Info(info)
            else -> null
        }

        val messagePlaceable = subcompose("message") {
            AnimatedContent(state) { state -> ... }
        }.first().measure(constraints)

        layout(messagePlaceable.width, messagePlaceable.height) {
            messagePlaceable.placeRelative(0, 0)
        }
    }

hrach avatar Jun 09 '23 13:06 hrach

Solution to this: https://android-review.googlesource.com/c/platform/frameworks/support/+/2640210

hrach avatar Oct 14 '23 10:10 hrach