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

60 ScrollBox #79

Merged
merged 8 commits into from
Jun 30, 2023
Merged

60 ScrollBox #79

merged 8 commits into from
Jun 30, 2023

Conversation

CyberDex
Copy link
Member

@CyberDex CyberDex commented Jun 29, 2023

Closes #60

The issue is that when user starts to drag scroll box, we should cancel the click if mouse was down on some element and this element or some of it's children has subscriptions to click.

Before, trying to fix this It was disabling interactivity for all the elements, but not their children, this was a reason of this issue.

Now instead of disabling interactivity for all the children, when down event performed on the ScrollBox, I check if down coordinate is on some of visible children. Then I go throughout the tree of its children and disable interactivity, storing the interactive elements. After the scroll is done, I restore interactivity from the list that I have stored.

Also refactored List component a bit and improved docs...

@CyberDex CyberDex linked an issue Jun 29, 2023 that may be closed by this pull request
@@ -7,6 +7,7 @@ export type ListOptions = {
children?: Container[];
vertPadding?: number;
horPadding?: number;
items?: Container[];
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a small refactor for a config consistency

Comment on lines -171 to -192
child.x = this.freeSlot.x;
child.y = this.freeSlot.y;
child.eventMode = 'static';

this.list.addChild(child);

if (!this.options.disableDynamicRendering)
{
child.renderable = this.isItemVisible(child);
}

const elementsMargin = this.options?.elementsMargin ?? 0;

switch (this.options.type)
{
case 'horizontal':
this.freeSlot.x += elementsMargin + child.width;
break;

default:
this.freeSlot.y += elementsMargin + child.height;
break;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was excess, this functionality actually is handled by the List component.

Comment on lines -57 to -61
protected readonly freeSlot = {
x: 0,
y: 0,
};

Copy link
Member Author

Choose a reason for hiding this comment

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

This was excess, this functionality actually is handled by the List component.

Comment on lines +325 to +337

const listTouchPoint = this.list.worldTransform.applyInverse(e.global);

this.visibleItems.forEach((item) =>
{
if (item.x < listTouchPoint.x
&& item.x + item.width > listTouchPoint.x
&& item.y < listTouchPoint.y
&& item.y + item.height > listTouchPoint.y)
{
this.pressedChild = item;
}
});
Copy link
Member Author

Choose a reason for hiding this comment

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

Detecting if pressed on some of visible children...

Comment on lines +366 to +370
if (this.pressedChild)
{
this.disableInteractivity(this.items);
this.revertClick(this.pressedChild);

this.pressedChild = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

During dragging started and if was pressed on some item, revert click for it.

Comment on lines -348 to -387
// prevent interactivity on all children
protected disableInteractivity(items: DisplayObject[])
{
items.forEach((item, id) =>
{
this.emitPointerOpOutside(item);

if (item.interactive)
{
this.interactiveStorage.set(id, item);
item.eventMode = 'auto';
item.interactiveChildren = false;
}
});
}

protected emitPointerOpOutside(item: DisplayObject)
{
if (item.eventMode !== 'auto')
{
item.emit('pointerupoutside', null);
}

if (item instanceof Container && item.children)
{
item.children.forEach((child) => this.emitPointerOpOutside(child));
}
}

// restore interactivity on all children that had it
protected restoreInteractivity()
{
this.interactiveStorage.forEach((item, itemID) =>
{
item.eventMode = 'static';
item.interactiveChildren = false;
this.interactiveStorage.delete(itemID);
});
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with new methods at the bottom of the file

@@ -47,8 +47,6 @@ export const UseGraphics: StoryFn = ({

for (let i = 0; i < itemsAmount; i++)
{
const buttonWrapper = new Container();
Copy link
Member Author

Choose a reason for hiding this comment

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

This was added before to test the issue. Removing now, to keep example cleaner.

@CyberDex CyberDex force-pushed the 60-scrollbox branch 2 times, most recently from fb16b57 to a041f30 Compare June 30, 2023 07:19
{
this.stopRenderHiddenItems();
this.list[type] = this._trackpad[type];
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a refactor

@CyberDex CyberDex merged commit 37e9e8f into main Jun 30, 2023
3 checks passed
@CyberDex CyberDex deleted the 60-scrollbox branch June 30, 2023 12:22
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.

ScrollBox
2 participants