Add ShrinkBehavior for stack children
ShrinkBehavior allows stack children to specify whether they should fill the available space when shrinking (the behavior today), or be re-measured in the new smaller space and "fitted" to that new size.
This allows you to improve behavior when an elements "intrinsic" size can change based on the available space - for example, a label that wraps.
Concretely, in MarketRow we use a Row to build the content:
|-Row-------------------------------|
| Leading | Text Content | Trailing |
|-----------------------------------|
In the case where Text Content consists of another Row with a multiline-label flexible followed by a fixed label, there can be undesired spacing introduced. This is because the label is measured within the constraint of the Row, then shrunk to fit, causing words to wrap that may not have been wrapped, which reduces the width of the text. However, the Row doesn't know this and can't currently account for it.
Desired behavior:
|-Row-------------------------------------------|
| | Multiline | |
| Leading | Text Label | Trailing |
| | Content | |
|-----------------------------------------------|
Actual behavior:
|-Row-------------------------------------------|
| | Multiline | |
| Leading | Text Label | Trailing |
| | Content | |
|-----------------------------------------------|
In this case, specifying .fit for the shrink behavior tells the row to re-measure the label when it shrinks it, resulting in the desired behavior.
Open Questions
Should this be automatic? We could measure shrunk children and use the new measurement if it's smaller than the original. I think it's usually desired, but doing it automatically means more measurements vs. opting in. On the other hand, the bug the current behavior introduces is pretty subtle and it's not obvious how to fix it, so it might be worth it - possibly worth profiling
Todo
- [ ] Update changelog
- [ ] Refine implementation, probably
Should this be automatic? We could measure shrunk children and use the new measurement if it's smaller than the original. I think it's usually desired, but doing it automatically means more measurements vs. opting in { ... }
I would make it opt in. There's already a pretty expensive cost to nesting multiple rows/columns due to the re-measurements in many cases; and this would have a penalty for all existing rows.
(Also in general; just keeping the layout behavior "as is" is probably better so we don't accidentally break things?)
Based on doing some preliminary testing in Market, I think this PR https://github.com/square/Blueprint/pull/348 ends up resolving this issue somewhat, because the measurement now takes place in a much more realistic size.
Closing, given that https://github.com/square/Blueprint/pull/348 addresses this for the most part