Giter Site home page Giter Site logo

Comments (11)

NickGerleman avatar NickGerleman commented on May 18, 2024 1

can I work on this?

Contributions are welcome šŸ™‚. Are you familiar with Yoga's system for test fixtures.

from yoga.

goolAdapter avatar goolAdapter commented on May 18, 2024 1

Hello, I meet this exactly issue in my work.and Iā€™m trying to fix it.

from yoga.

cattenblue avatar cattenblue commented on May 18, 2024 1

I encountered the same issue and had a doubt about why clamping to the min/max size specified on the container is needed for each line. So, I tried removing it for each line, and I add three test. Here is my submission #1493

from yoga.

NextThread avatar NextThread commented on May 18, 2024

can I work on this?

from yoga.

NextThread avatar NextThread commented on May 18, 2024

can I work on this?

Contributions are welcome šŸ™‚. Are you familiar with Yoga's system for test fixtures.

Yeah,
Okay thanks

from yoga.

NextThread avatar NextThread commented on May 18, 2024

@rasjonell hey can you try this?

const childHeightSum = node1.getComputedHeight() + node2.getComputedHeight();
const minHeight = container.getStyle().minHeight;

if (childHeightSum < minHeight) {
  container.setHeight(minHeight);
} else {
  container.setHeight(childHeightSum);
}

const height = container.getComputedHeight();

from yoga.

rasjonell avatar rasjonell commented on May 18, 2024

@rasjonell hey can you try this?

const childHeightSum = node1.getComputedHeight() + node2.getComputedHeight();
const minHeight = container.getStyle().minHeight;

if (childHeightSum < minHeight) {
  container.setHeight(minHeight);
} else {
  container.setHeight(childHeightSum);
}

const height = container.getComputedHeight();

This won't work. First I can't just rely on the sum of computed heights, as not all elements are necessarily wrapped, for example I may have a case like this:

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
ā”‚                                 ā”‚ Each box has size: 100 x 300
ā”‚                                 ā”‚ The sum of children heights would be: 1200
ā”‚  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”   ā”‚ If it happens to be greater than the container's minHeight,
ā”‚  ā”‚      ā”‚  ā”‚      ā”‚  ā”‚      ā”‚   ā”‚ The final height would be 1200, instead 600
ā”‚  ā”‚   1  ā”‚  ā”‚   2  ā”‚  ā”‚   3  ā”‚   ā”‚
ā”‚  ā”‚      ā”‚  ā”‚      ā”‚  ā”‚      ā”‚   ā”‚
ā”‚  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”˜   ā”‚
ā”‚                                 ā”‚
ā”‚                                 ā”‚
ā”‚  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”                       ā”‚
ā”‚  ā”‚      ā”‚                       ā”‚
ā”‚  ā”‚  4   ā”‚                       ā”‚
ā”‚  ā”‚      ā”‚                       ā”‚
ā”‚  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                       ā”‚
ā”‚                                 ā”‚
ā”‚                                 ā”‚
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

If I collect the sum of heights it won't represent the height of all the rows. I would have to also make some calculations to understand how many rows are there and then calculate the sum, which can be really expensive, considering every layout change would make the same calculation twice(once on yoga's side, once on my own).

Another potential issue with this approach is that I would lose my minHeigt option afterwards as we are setting container.setHeight()

from yoga.

NextThread avatar NextThread commented on May 18, 2024

can we follow the below approach?

  • We'll iterate through the child nodes and determine if adding each child to the current row would exceed the
    minHeight property of the container.
  • If the addition of a child to the current row would exceed minHeight, we start a new row.
  • We keep track of the total height by summing up the heights of each row.
  • After iterating through all child nodes, we calculate the final height of the container by considering the total height and
    the minHeight property.
  • We then set the container's height to the calculated final height.
const childNodes = container.getChildNodes();
const childNodeCount = childNodes.length;

let currentRowHeight = 0;
let totalHeight = 0;
let numRows = 1;

for (let i = 0; i < childNodeCount; i++) {
  const childNode = childNodes[i];
  const childHeight = childNode.getComputedHeight();
  
  if (currentRowHeight + childHeight <= minHeight) {
    currentRowHeight += childHeight;
  } else {
    totalHeight += currentRowHeight;
    currentRowHeight = childHeight;
    numRows++;
  }
}

totalHeight += currentRowHeight;

const finalHeight = Math.max(minHeight, totalHeight);
container.setHeight(finalHeight);

from yoga.

rasjonell avatar rasjonell commented on May 18, 2024

Yes, this workaround will fix it, however it's really expensive, considering my client would need to recalculate stuff that's already calculated on Yoga's side. Also I would lose the minHeight config as we are setting the height property.

from yoga.

NickGerleman avatar NickGerleman commented on May 18, 2024

@NextThread have you looked at fixing this inside of Yoga, instead of recommending workarounds?

from yoga.

NextThread avatar NextThread commented on May 18, 2024

@NextThread have you looked at fixing this inside of Yoga, instead of recommending workarounds?

No, I'm a beginner so, before that I was trying to share my approach,

should I try?

from yoga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.