cx-cocos/cx-framework3.1/cx/scripts/cxui.page.ts

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-06-07 07:13:32 +00:00
import {_decorator, Component, Node, EventTouch, Tween, tween} from 'cc';
const {ccclass} = _decorator;
@ccclass('cxui.page')
class CxuiPage extends Component
{
onLoad ()
{
cx.makeNodeMap(this.node);
this.node.on(Node.EventType.TOUCH_START, (event: EventTouch) =>
{
event.propagationStopped = true;
});
}
/* pageonLoad
this.initPx: 初始位置
this.initPy: 初始位置
this.moveInAction: 进入动画
this.nextInAction: 进入时
this.moveOutAction: 关闭动画
this.nextOutAction: 关闭时
*/
public initPx?: number;
public initPy?: number;
public moveInAction?: Tween<any>;
public nextInAction?: Tween<any>;
public moveOutAction?: Tween<any>;
public nextOutAction?: Tween<any>;
runActionShow ()
{
if (cx.os.android)
this.node.androidBackHandler = "closePage";
if (cx.config.pageActionDisabled || this.node.pageActionDisabled)
return;
var x = this.initPx != undefined ? this.initPx : cx.defaultInitPx;
var y = this.initPy != undefined ? this.initPy : cx.defaultInitPy;
this.node.setPosition(x, y);
tween(this.node).then(this.moveInAction || cx.defaultMoveInAction).start();
var priorPage = cx.getTopPage(-1);
if (priorPage)
{
tween(priorPage).then(this.nextInAction || cx.defaultNextInAction).start();
var priorMask: any = priorPage.getComponent("cxui.nativeMask");
if (priorMask)
priorMask.setMonitorNode(this.node);
}
}
runActionClose ()
{
var priorPage = cx.getTopPage(-1);
if (priorPage && priorPage.mainComponent && priorPage.mainComponent.onChildPageClosed)
priorPage.mainComponent.onChildPageClosed.call(priorPage.mainComponent, this.node.mainComponent);
if (cx.config.pageActionDisabled || this.node.pageActionDisabled)
{
this.node.destroy();
return;
}
tween(this.node).then(this.moveOutAction || cx.defaultMoveOutAction).call(()=>{this.node.destroy();}).start();
if (priorPage)
{
tween(priorPage).then(this.nextOutAction || cx.defaultNextOutAction).start();
// var priorMask = priorPage.getComponent("cxui.nativeMask");
// if (priorMask)
// priorMask.setMonitorNode();
}
}
}