diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 4ae994f..99ed184 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -6,7 +6,7 @@ import { } from 'pixi.js' import { patchProp } from './patch' import { elements } from './elements' -import { isCustomFilter } from './utils' +import { isCustomFilter, isExistsEvent } from './utils' interface CreatePixiRendererOptions { prefix?: string @@ -21,8 +21,11 @@ export function createPixiRenderer(options: CreatePixiRendererOptions = {}) { ? props?.is?.(props) : createPixiElement(prefix, name, props) - if (element instanceof Container) + if (element instanceof Container) { element.filters = [] + if (isExistsEvent(props) && element.eventMode === 'auto') + element.eventMode = 'static' + } return element }, diff --git a/src/renderer/patch.ts b/src/renderer/patch.ts index 6d68cdf..87b2cf3 100644 --- a/src/renderer/patch.ts +++ b/src/renderer/patch.ts @@ -175,7 +175,8 @@ export function patchEventProps(el: Container, key: string, prevValue: any, next const eventName = key.slice(2).toLowerCase() if (prevValue) el.off(eventName as any, prevValue) - el.on(eventName as any, nextValue) + if (nextValue) + el?.on(eventName as any, nextValue) return true } return false diff --git a/src/renderer/utils.ts b/src/renderer/utils.ts index 954dfec..1de36a6 100644 --- a/src/renderer/utils.ts +++ b/src/renderer/utils.ts @@ -15,3 +15,7 @@ export function isCustomFilter(prefix: string, name: string) { isPrefix && name.slice(prefix.length) === 'Filter' ) || name === 'Filter' } + +export function isExistsEvent(props: any = {}) { + return Object.keys(props).some(p => p.startsWith('on')) +}