Commit f9cb43f2 authored by rockyl's avatar rockyl

toast增加更多参数

parent 6a30b259
...@@ -17298,6 +17298,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -17298,6 +17298,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}; };
return StackContainer; return StackContainer;
}(Node$1)); }(Node$1));
//# sourceMappingURL=StackContainer.js.map
var colorName = { var colorName = {
"aliceblue": [240, 248, 255], "aliceblue": [240, 248, 255],
...@@ -20185,14 +20186,14 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20185,14 +20186,14 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Toast.prototype.show = function (props) { Toast.prototype.show = function (props) {
if (props === void 0) { props = {}; } if (props === void 0) { props = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__awaiter(this, void 0, void 0, function () {
var contentView, lab, text, _a, padding, _b, duration, _c, showDuration, _d, hideDuration; var contentView, lab, text, _a, padding, paddingH, paddingV, _b, duration, _c, showDuration, _d, hideDuration;
return tslib_1.__generator(this, function (_e) { return tslib_1.__generator(this, function (_e) {
switch (_e.label) { switch (_e.label) {
case 0: case 0:
if (!props.text) { if (!props.text) {
return [2]; return [2];
} }
return [4, this.getContent(props.viewName)]; return [4, this.getContent(props.viewName, props)];
case 1: case 1:
contentView = _e.sent(); contentView = _e.sent();
lab = contentView.getChildByName('lab'); lab = contentView.getChildByName('lab');
...@@ -20200,11 +20201,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20200,11 +20201,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
console.warn('[lab] child no exists on toast view'); console.warn('[lab] child no exists on toast view');
return [2]; return [2];
} }
text = props.text, _a = props.padding, padding = _a === void 0 ? 10 : _a, _b = props.duration, duration = _b === void 0 ? 1000 : _b, _c = props.showDuration, showDuration = _c === void 0 ? 300 : _c, _d = props.hideDuration, hideDuration = _d === void 0 ? 200 : _d; text = props.text, _a = props.padding, padding = _a === void 0 ? 10 : _a, paddingH = props.paddingH, paddingV = props.paddingV, _b = props.duration, duration = _b === void 0 ? 1000 : _b, _c = props.showDuration, showDuration = _c === void 0 ? 300 : _c, _d = props.hideDuration, hideDuration = _d === void 0 ? 200 : _d;
lab.text = text; lab.text = text;
lab.x = lab.y = padding; lab.x = paddingH || padding;
this.width = contentView.width = lab.width + padding * 2; lab.y = paddingV || padding;
this.height = contentView.height = lab.height + padding * 2; this.width = contentView.width = lab.width + (paddingH || padding) * 2;
this.height = contentView.height = lab.height + (paddingV || padding) * 2;
if (!contentView.visible) { if (!contentView.visible) {
contentView.visible = true; contentView.visible = true;
contentView.alpha = 0; contentView.alpha = 0;
...@@ -20240,33 +20242,34 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20240,33 +20242,34 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.removeChild(this._content); this.removeChild(this._content);
this._content = null; this._content = null;
}; };
Toast.prototype.getContent = function (viewName) { Toast.prototype.getContent = function (viewName, props) {
return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__awaiter(this, void 0, void 0, function () {
var view, bg, lab; var view, _a, borderRadius, _b, labColor, _c, labSize, _d, bgColor, _e, bgAlpha, bg, lab;
return tslib_1.__generator(this, function (_a) { return tslib_1.__generator(this, function (_f) {
switch (_a.label) { switch (_f.label) {
case 0: case 0:
if (!(this.children.length == 0)) return [3, 3]; if (!(this.children.length == 0)) return [3, 3];
if (!viewName) return [3, 2]; if (!viewName) return [3, 2];
return [4, this._gameStage.instantiateView(viewName)]; return [4, this._gameStage.instantiateView(viewName)];
case 1: case 1:
view = _a.sent(); view = _f.sent();
_a.label = 2; _f.label = 2;
case 2: case 2:
if (!view) { if (!view) {
if (!this._contentSample) { if (!this._contentSample) {
_a = props.borderRadius, borderRadius = _a === void 0 ? 10 : _a, _b = props.labColor, labColor = _b === void 0 ? 'white' : _b, _c = props.labSize, labSize = _c === void 0 ? 30 : _c, _d = props.bgColor, bgColor = _d === void 0 ? 'black' : _d, _e = props.bgAlpha, bgAlpha = _e === void 0 ? 0.7 : _e;
this._contentSample = new Node$1(); this._contentSample = new Node$1();
bg = new Rect(); bg = new Rect();
bg.borderRadius = 10; bg.borderRadius = borderRadius;
bg.percentWidth = 100; bg.percentWidth = 100;
bg.percentHeight = 100; bg.percentHeight = 100;
bg.fillColor = 'black'; bg.fillColor = bgColor;
bg.alpha = 0.7; bg.alpha = bgAlpha;
this._contentSample.addChild(bg); this._contentSample.addChild(bg);
lab = new Label(); lab = new Label();
lab.name = 'lab'; lab.name = 'lab';
lab.fillColor = 'white'; lab.fillColor = labColor;
lab.size = 30; lab.size = labSize;
this._contentSample.addChild(lab); this._contentSample.addChild(lab);
} }
view = this._contentSample; view = this._contentSample;
...@@ -20276,7 +20279,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20276,7 +20279,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return [3, 4]; return [3, 4];
case 3: case 3:
view = this.getChildAt(0); view = this.getChildAt(0);
_a.label = 4; _f.label = 4;
case 4: return [2, view]; case 4: return [2, view];
} }
}); });
...@@ -20284,7 +20287,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20284,7 +20287,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}; };
return Toast; return Toast;
}(Node$1)); }(Node$1));
//# sourceMappingURL=Toast.js.map
function createEvalFunc(exp) { function createEvalFunc(exp) {
var func; var func;
......
This diff is collapsed.
{"id":"engine","url":"engine.50f2306185a286c24568fc87ef21dd4070b56456.js"} {"id":"engine","url":"engine.68ebcc028b764acc0a822ad13fce52e3f9744bcb.js"}
\ No newline at end of file \ No newline at end of file
...@@ -28,18 +28,19 @@ export class Toast extends Node { ...@@ -28,18 +28,19 @@ export class Toast extends Node {
return; return;
} }
let contentView = await this.getContent(props.viewName); let contentView = await this.getContent(props.viewName, props);
let lab = contentView.getChildByName('lab'); let lab = contentView.getChildByName('lab');
if (!lab) { if (!lab) {
console.warn('[lab] child no exists on toast view'); console.warn('[lab] child no exists on toast view');
return; return;
} }
const {text, padding = 10, duration = 1000, showDuration = 300, hideDuration = 200} = props; const {text, padding = 10, paddingH, paddingV, duration = 1000, showDuration = 300, hideDuration = 200} = props;
lab.text = text; lab.text = text;
lab.x = lab.y = padding; lab.x = paddingH || padding;
this.width = contentView.width = lab.width + padding * 2; lab.y = paddingV || padding;
this.height = contentView.height = lab.height + padding * 2; this.width = contentView.width = lab.width + (paddingH || padding) * 2;
this.height = contentView.height = lab.height + (paddingV || padding) * 2;
if (!contentView.visible) { if (!contentView.visible) {
contentView.visible = true; contentView.visible = true;
...@@ -55,11 +56,11 @@ export class Toast extends Node { ...@@ -55,11 +56,11 @@ export class Toast extends Node {
hide(animation = true, hideDuration = 200) { hide(animation = true, hideDuration = 200) {
if (this._content) { if (this._content) {
const contentView = this._content; const contentView = this._content;
if(animation){ if (animation) {
Tween.get(contentView, null, null, true) Tween.get(contentView, null, null, true)
.to({alpha: 0}, hideDuration) .to({alpha: 0}, hideDuration)
.call(this.removeContentView, this) .call(this.removeContentView, this)
}else{ } else {
Tween.removeTweens(contentView); Tween.removeTweens(contentView);
this.removeContentView(); this.removeContentView();
} }
...@@ -72,7 +73,7 @@ export class Toast extends Node { ...@@ -72,7 +73,7 @@ export class Toast extends Node {
this._content = null; this._content = null;
} }
private async getContent(viewName) { private async getContent(viewName, props) {
let view; let view;
if (this.children.length == 0) { if (this.children.length == 0) {
...@@ -81,18 +82,20 @@ export class Toast extends Node { ...@@ -81,18 +82,20 @@ export class Toast extends Node {
} }
if (!view) { if (!view) {
if (!this._contentSample) { if (!this._contentSample) {
const {borderRadius = 10, labColor = 'white', labSize = 30, bgColor = 'black', bgAlpha = 0.7} = props;
this._contentSample = new Node(); this._contentSample = new Node();
let bg = new Rect(); let bg = new Rect();
bg.borderRadius = 10; bg.borderRadius = borderRadius;
bg.percentWidth = 100; bg.percentWidth = 100;
bg.percentHeight = 100; bg.percentHeight = 100;
bg.fillColor = 'black'; bg.fillColor = bgColor;
bg.alpha = 0.7; bg.alpha = bgAlpha;
this._contentSample.addChild(bg); this._contentSample.addChild(bg);
let lab = new Label(); let lab = new Label();
lab.name = 'lab'; lab.name = 'lab';
lab.fillColor = 'white'; lab.fillColor = labColor;
lab.size = 30; lab.size = labSize;
this._contentSample.addChild(lab); this._contentSample.addChild(lab);
} }
view = this._contentSample; view = this._contentSample;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment