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

Fix for bugs when no compaction is on. #766

Merged

Conversation

brian-eightsolutions
Copy link

@brian-eightsolutions brian-eightsolutions commented Mar 22, 2018

Both of these fixes are for when there is no compaction. See #750

For moveElementAwayFromCollision(), the issue is that if there is no compaction, compactH and compactV are both false, and no collision is resolved at all. The solution to this is to apply the vertical collision logic if compactH is not true ie. in all other instances. This is valid as there are other instances in the code that make the same assumption.

For resolveCompactionCollision(), the code was detecting an item's collision with itself, thus moving everything down too far. This isn't a noticable problem when there is compaction, as it will resolve all the items moving down too far afterwards by compacting them back up, but the logic is still incorrect. When compaction is off though, the tiles get pushed down too far and remain there, leaving empty blank space.

Thanks!
Brian

lib/utils.js Outdated
@@ -192,6 +192,8 @@ function resolveCompactionCollision(
const otherItem = layout[i];
// Ignore static items
if (otherItem.static) continue;
// Don't resolve collision if with itself
if (otherItem.i === item.i) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be possible given that we iterate through the list starting past this item. Have you seen it compare with itself before?

Choose a reason for hiding this comment

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

Yes, I have seen it happen. I checked again, and it is happening because itemIndex is being calculated incorrectly. It is trying to use Array.prototype.indexOf() to find the index of an object, which will not work. I have updated the fix to address the root issue instead.

I just noticed a similar issue is happening in collides(). It will never detect that it is checking whether an item is colliding with itself, as === can't be used to check object equality. I've changed it to compare the i key instead.

lib/utils.js Outdated
@@ -441,7 +443,8 @@ export function moveElementAwayFromCollision(
cols: number
): Layout {
const compactH = compactType === "horizontal";
const compactV = compactType === "vertical";
// Compact vertically if not set to horizontal
const compactV = compactType !== 'horizontal';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good call, we need to resolve the collision somehow.

@brian-eightsolutions brian-eightsolutions force-pushed the fix-for-no-compaction branch 2 times, most recently from 34924b8 to ab90d33 Compare March 26, 2018 18:04
@STRML STRML merged commit 073e976 into react-grid-layout:master Mar 28, 2018
@STRML
Copy link
Collaborator

STRML commented Mar 28, 2018

Thanks!

@makis-spy
Copy link

Hi! Sorry to bring this up again but were these "bugs" solved in a previous version ? I'm seeing the behavior in latest.

Thanks!

@STRML STRML added this to the 0.17.0 milestone Oct 22, 2019
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.

None yet

3 participants