androidx / constraintlayout

ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way
Apache License 2.0
1.06k stars 177 forks source link

[JSON] Enable match_parent width and height for Flow #709

Closed jswong65 closed 1 year ago

jswong65 commented 1 year ago

The main objective this PR is to enable match_parent for the width and height of a Flow for the JSON representation. Also, I updated the existing demos and added more demos for this change.

image image

Previously, when we set match_parent for the width and height, it won't work properly. The main reason is that when the constraints function is invoked in https://github.com/androidx/constraintlayout/blob/main/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/State.java#L544 it would created a new reference for the Flow. However, the new created reference has the default values of mHorizontalDimension and mVerticalDimension as WRAP_CONTENT. Therefore, no matter what values are set in the flowReference, the WRAP_CONTENT value will still be applied.

Other issues to be resolved

Fixed value for width and height

There is still an issue setting a fixed value for the width and height of a Flow (see FlowInvalidDemo1 as an example). I am still investigating the cause, but I suspect that we might need to treat a Flow helper as a measurable to make the Flow itself be properly measured. For example, https://github.com/androidx/constraintlayout/blob/ea5299efaeed6ca8cd55267faf929f15c33aa8dc/constraintlayout/compose/src/main/java/androidx/constraintlayout/compose/ConstraintLayout.kt#L994.

Issue with the Id

Another issue need to be investigated is that the id of a button would affect the result of the solver. For example, if I set the id of a button as "1" or "a", the left position value would become 0 (see FlowInvalidDemo2 as an example)

image

However, if I change the id to "btn1", it would then work as expected.

image
oscar-ad commented 1 year ago
There is still an issue setting a fixed value for the width and height of a Flow (see FlowInvalidDemo1 as an example). I am still investigating the cause, but I suspect that we might need to treat a Flow helper as a measurable to make the Flow itself be properly measured. For example,

constraintlayout/constraintlayout/compose/src/main/java/androidx/constraintlayout/compose/ConstraintLayout.kt

Line 994 in ea5299e

 if (measurable !is Measurable) return 
.

Sounds about right, I might have a solution for it.