Skip to content

Fix/ ColorPalette scrolling and extra renders #2179

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

Merged
merged 4 commits into from
Aug 10, 2022
Merged

Conversation

lidord-wix
Copy link
Contributor

Description

The issues:

  1. ColorPalette renders all the swatches on every swatch selection because it creates new refs every time.
  2. The scrolling to the selected Swatch doesn't work (both for existing palettes with many colors and for the added color in a ColorPicker)
    This PR fixes the two issues.
    I used a hack for the scrolling - the offset of the last added color is bad (always 10) , so I calculate the one before the last and add the extra offset.
    Let me know I you have any ideas (setTimeout doesn't fix anything),

Changelog

Fix ColorPalette scrolling and extra renders

_.times(this.props.colors.length, i => {
this.itemsRefs.current[i] = React.createRef();
});
setTimeout(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider moving setTimeout to scrollToSelected if it's being wrapped every time

if (scrollable && this.selectedColorIndex !== undefined && this.itemsRefs) {
const childRef = this.itemsRefs[this.selectedColorIndex];
if (scrollable && this.selectedColorIndex !== undefined && this.itemsRefs.current) {
const childRef: any = this.itemsRefs.current[this.selectedColorIndex - 1]?.current;
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't the selectedColorIndex is zero based? why the minus 1?

@lidord-wix lidord-wix merged commit e13bcb6 into master Aug 10, 2022
@lidord-wix lidord-wix deleted the perf/colorPalette branch August 22, 2022 11:56
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.

2 participants