Commit 6e583a84 authored by rockyl's avatar rockyl

修复图片和文本的相对布局的问题

增加Event.WINDOW_VISIBILITY_CHANGE事件表示页面可见性变化的时候的事件
parent 4644465a
This diff is collapsed.
This diff is collapsed.
{"id":"engine","url":"engine.8ae778db8ef99e121b1d622a45079bb758d196e1.js"}
\ No newline at end of file
{"id":"engine","url":"engine.cba09e24bd26909e1a67685a889d4799f4c2597a.js"}
\ No newline at end of file
......@@ -12,6 +12,7 @@
},
"devDependencies": {
"dts-bundle": "^0.7.3",
"dts-bundle-generator": "^4.3.0",
"glob": "^7.1.6",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
......@@ -29,9 +30,8 @@
"build:upload": "rm -rf dist&&yarn build:prod && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"build:debug": "rm -rf dist&&yarn build && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts",
"test": "echo \"Error: no test specified\" && exit 1",
"mergeDts": "node scripts/mergeDts.js",
"token": "uglifyjs -m -c -o px-token.min.js px-token.js"
"token": "uglifyjs -m -c -o px-token.min.js px-token.js",
"dts": "dts-bundle-generator -o types.d.ts src/index.ts"
},
"author": "",
"license": "ISC"
......
......@@ -250,6 +250,12 @@ export class Event extends HashObject {
* @type {string}
*/
public static UPDATE_DATA: string = "UPDATE_DATA";
/**
* 页面可见性变化
*/
public static WINDOW_VISIBILITY_CHANGE: string = 'window-visibility-change';
/**
* 事件类型名
* @property type
......
......@@ -187,6 +187,7 @@ export class TextField extends Sprite {
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
}
}
......@@ -208,6 +209,7 @@ export class TextField extends Sprite {
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
}
}
......@@ -903,6 +905,8 @@ export class TextField extends Sprite {
//修改texture及baseTexture属性
s.updateTexture();
this.dispatchEvent(Event.MAYBE_ALIGN);
function measureChar(char, index?) {
let key = char + ':';
......
......@@ -91,7 +91,11 @@ class AlignManager {
} else {
// 先设置下自己的 width
toBoolean(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100);
if(toBoolean(percentWidth)){
tW_Z = that.width = pW_Z * percentWidth / 100
}else{
tW_Z = that.width;
}
// 先考虑 horizonCenter 属性
if (toBoolean(horizonCenter)) {
......@@ -120,7 +124,11 @@ class AlignManager {
} else {
// 先设置下自己的 height
toBoolean(percentHeight) && (tH_Z = that.height = pH_Z * percentHeight / 100);
if(toBoolean(percentHeight)){
tH_Z = that.height = pH_Z * percentHeight / 100
}else{
tH_Z = that.height;
}
// 先考虑 horizonCenter 属性
if (toBoolean(verticalCenter)) {
......
......@@ -108,4 +108,10 @@ export class Image extends Sprite implements IUIComponent {
private onDataMutated(e = null) {
this._setSourceDirect(dataCenter.formatString(this._originText, this._escapes));
}
_onTextureUpdate() {
super._onTextureUpdate();
this.dispatchEvent(Event.MAYBE_ALIGN);
}
}
......@@ -44,6 +44,13 @@ function instantiateView(config) {
if (children && children.length > 0) {
for (let childConfig of children) {
if(childConfig.type=="editScrollView"){
childConfig.type="scrollView"
}
if(childConfig.type=="editScrollList"){
childConfig.type="scrollList"
}
const childNode = instantiateView(childConfig);
if (childNode) {
node.addChild(childNode);
......
......@@ -8,6 +8,8 @@ import {env} from "./game-warpper/enviroment";
import {queryParams} from "./web";
import {httpRequest} from "../2d/net";
import {injectProp} from "./utils/utils";
import {globalEvent} from "./decorators/events";
import {Event} from "../2d/events/Event";
export function dealPxEnv() {
//appID提取
......@@ -51,7 +53,7 @@ export function dealPxEnv() {
}
}
export function cleanNewUser(){
export function cleanNewUser() {
let key = 'nu_' + env.appID + '_' + env.projectID;
localStorage.removeItem(key);
}
......@@ -59,28 +61,18 @@ export function cleanNewUser(){
export function dealPageRemainTime() {
let startTimer = new Date().getTime();
let endTimer;
//设置隐藏属性和改变可见属性的事件的名称
let visibilityChange;
if (typeof document.hidden !== 'undefined') {
visibilityChange = 'visibilitychange';
} else if (typeof document['msHidden'] !== 'undefined') {
visibilityChange = 'msvisibilitychange';
} else if (typeof document['webkitHidden'] !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
}
const handleVisibilityChange = (e) => {
if (document.visibilityState == "visible") {
globalEvent.addEventListener(Event.WINDOW_VISIBILITY_CHANGE, (e) => {
if (e.data.visible) {
startTimer = new Date().getTime();
//console.log('starttimer', startTimer)
}
if (document.visibilityState == "hidden") {
} else {
endTimer = new Date().getTime();
//console.log('endTimer', endTimer);
sendData();
}
};
});
const sendData = () => {
const t0 = endTimer - startTimer;
......@@ -91,12 +83,6 @@ export function dealPageRemainTime() {
});
};
document.addEventListener(
visibilityChange,
handleVisibilityChange,
false
);
document.body['onbeforeunload'] = () => {
endTimer = new Date().getTime();
return sendData();
......
/**
* Created by rockyl on 2019-12-10.
*/
import {globalEvent,} from "./decorators/events";
import {Event,} from "../2d/events/Event";
export let queryParams: any = {};
......@@ -50,3 +52,27 @@ function _appendScript(scriptContent, parent) {
scriptEl.innerHTML = scriptContent;
parent.appendChild(scriptEl);
}
function windowVisibility() {
//设置隐藏属性和改变可见属性的事件的名称
let visibilityChange;
if (typeof document.hidden !== 'undefined') {
visibilityChange = 'visibilitychange';
} else if (typeof document['msHidden'] !== 'undefined') {
visibilityChange = 'msvisibilitychange';
} else if (typeof document['webkitHidden'] !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
}
const handleVisibilityChange = (e) => {
globalEvent.dispatchEvent(Event.WINDOW_VISIBILITY_CHANGE, {visible: document.visibilityState == "visible"})
};
document.addEventListener(
visibilityChange,
handleVisibilityChange,
false
);
}
windowVisibility();
This diff is collapsed.
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