-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
60 ScrollBox #79
Conversation
@@ -7,6 +7,7 @@ export type ListOptions = { | |||
children?: Container[]; | |||
vertPadding?: number; | |||
horPadding?: number; | |||
items?: Container[]; |
There was a problem hiding this comment.
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
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; | ||
} |
There was a problem hiding this comment.
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.
protected readonly freeSlot = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
|
There was a problem hiding this comment.
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.
|
||
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; | ||
} | ||
}); |
There was a problem hiding this comment.
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...
if (this.pressedChild) | ||
{ | ||
this.disableInteractivity(this.items); | ||
this.revertClick(this.pressedChild); | ||
|
||
this.pressedChild = null; |
There was a problem hiding this comment.
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.
// 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); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
fb16b57
to
a041f30
Compare
{ | ||
this.stopRenderHiddenItems(); | ||
this.list[type] = this._trackpad[type]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a refactor
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...