Skip to content

Commit

Permalink
fix(event): automatically set event mode after referencing events (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr.Mao committed May 9, 2023
1 parent 51f0846 commit 277bbaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
},
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}

0 comments on commit 277bbaa

Please sign in to comment.