[LayaAir 2.0]Button点击函数逻辑bug

onMouse(e) {
if (this.toggle === false && this._selected)
return;
if (e.type === Laya.Event.CLICK) {
this.toggle && (this.selected = !this._selected);
this._clickHandler && this._clickHandler.run();
return;
}
!this._selected && (this.state = Button.stateMap[e.type]);
}
上面逻辑当clickHander只执行一次的时候逻辑上有bug,Hander的run执行的时候如果只执行一次会被回收,这个时候button又持有引用,如果其他地方用到了这个Handler,点击按钮就会执行到其他地方导致真正该执行的地方无法执行。
应该修改为:
__proto.onMouse=function(e){
if (this.toggle===false && this._selected)return;
if (e.type===/*laya.events.Event.CLICK*/"click"){
this.toggle && (this.selected=!this._selected);
if(this._clickHandler){
var handler = this._clickHandler;
if(handler.once){
this._clickHandler = null;
}
handler.run();
}
return;
}
!this._selected && (this.state=Button.stateMap[e.type]);
}
bug.png
已邀请:

Aar0n

赞同来自:

感谢反馈,核实后会修改,也可以在git上直接 提交代码

要回复问题请先

商务合作
商务合作