Percentage padding not updated when the parent size changes
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18.9k
- Forks
- 1.6k
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
Report
When a child has a percentage padding, it is initially correct in regard to the parent's size, but it is not updated in subsequent Yoga executions unless the child becomes dirty.
I am testing this with the Javascript Yoga npm package v2.0.1, but this may be an issue with the layout engine.
- I have searched existing issues and this is not a duplicate
- I can't imagine this hasn't been reported, but I searched for issues with keywords "percent" and "percentage". This is the only issue of interest that I found, but I don't think it's related: https://github.com/facebook/yoga/issues/930
Issues and Steps to Reproduce
Here is some very basic code with console output to reproduce.
function percentPadding(yoga) {
const config = yoga.Config.create();
config.setPointScaleFactor(0);
const parent = yoga.Node.createWithConfig(config);
parent.setWidth(10);
const child = yoga.Node.createWithConfig(config);
child.setWidth(5);
child.setPaddingPercent(Edge.Left, 50);
parent.insertChild(child, 0);
// On the first execution, the child's padding is as expected: 50% * 10 = 5.
console.log("** Executing **");
parent.calculateLayout(10, 10);
console.log(`Child - padding left: ${child.getComputedPadding(Edge.Left)}`);
// Now change the parent width to 5. The expected child padding is: 50% * 5 = 2.5.
// However, we can see that the padding is still 5.
parent.setWidth(5);
console.log("** Executing **");
parent.calculateLayout(10, 10);
console.log(`Child - padding left: ${child.getComputedPadding(Edge.Left)}`);
// If we make an arbitrary change, just to make the child dirty, the padding is now correct at 2.5
child.setBorder(Edge.Top, 0);
console.log("** Executing **");
parent.calculateLayout(10, 10);
console.log(`Child - padding left: ${child.getComputedPadding(Edge.Left)}`);
}
function main() {
const yoga = await loadYoga();
percentPadding(yoga);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied JavaScript Yoga reproduction using the npm package, focusing on calculateLayout, setWidth, setPaddingPercent, and getComputedPadding. Trace the layout engine path that runs after the parent width changes without dirtying the child. Done means the second execution reports 2.5 for the child's left padding without the arbitrary border change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100