Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masonry: Enable dynamic batches #3875

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bryamrrr
Copy link
Contributor

@bryamrrr bryamrrr commented Nov 15, 2024

Summary

What changed?

This PR introduces _getModulePositioningConfig, an experimental prop to enable dynamic batch sizes (and Early bailout). This is a way to dynamically set the number of items used to position a multicolumn module.

_getModulePositioningConfig uses two params (gridSize and moduleSize) and uses them to return a ModulePositioningConfig, which could have these values:

  • itemsBatchSize: Maximum number of items used to position a module
  • whitespaceThreshold: "Good enough" whitespace number when positioning a module
  • iterationsLimit: Optional hard limit for DAG iterations

Why?

This will allow us to reduce the whitespace from larger multicolumn modules.

Other changes:

  • Refactor to enable a gutter at the Masonry and MasonryV2 level. This way, we can have the gutter logic in a single place and use it everywhere is needed.
  • Refactor of GetColumnCount to move the logic to know how many columns a grid have in a single place

Images confirming we have the correct module and grid sizes.

Screenshot 2024-11-14 at 3 41 41 p m Screenshot 2024-11-14 at 3 41 13 p m

@bryamrrr bryamrrr requested a review from a team as a code owner November 15, 2024 01:32
Comment on lines +718 to +720
const gridSize = getColumnCount({ gutter, columnWidth, width, minCols, layout });

const moduleSize = calculateActualColumnSpan({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the tricky part of this implementation. These two values are easy to find in multiColumnLayout.ts, but are not ready at this scope.

  • For grid size, I created a whole new util that abstract the way we calculate the column count from both DefaultLayout and FullWidthLayout (updating those utils to avoid code duplicity too).
  • For moduleSize, I exposed the calculateActualColumnSpan from multiColumnLayout.ts to be able to use it here.

All of this happens also in MasonryV2.

Copy link

netlify bot commented Nov 15, 2024

Deploy Preview for gestalt ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d9e4c8f
🔍 Latest deploy log https://app.netlify.com/sites/gestalt/deploys/67460ca318fa870008e875fc
😎 Deploy Preview https://deploy-preview-3875--gestalt.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant