46 lines
3.0 KiB
JavaScript
46 lines
3.0 KiB
JavaScript
var TITLE = "1'me肌肤状态检测";
|
|
function positive(value) { return typeof value === 'number' && isFinite(value) && value > 0; }
|
|
function layout(platform) {
|
|
var info = {};
|
|
try { if (platform && typeof platform.getSystemInfoSync === 'function') info = platform.getSystemInfoSync() || {}; } catch (_) {}
|
|
var top = positive(info.statusBarHeight) ? info.statusBarHeight :
|
|
info.safeArea && positive(info.safeArea.top) ? info.safeArea.top : 20;
|
|
var bar = positive(info.titleBarHeight) ? info.titleBarHeight : 44;
|
|
return { title: TITLE, top: top, bar: bar, height: top + bar, showTitle: true };
|
|
}
|
|
function page(definition, platform, options) {
|
|
options = options || {};
|
|
definition.data = Object.assign({ brandHeader: layout() }, definition.data);
|
|
var load = definition.onLoad, resize = definition.onResize, show = definition.onShow,
|
|
ready = definition.onReady, hide = definition.onHide, unload = definition.onUnload;
|
|
function refresh(instance) {
|
|
var next = layout(platform);
|
|
if (instance.data.brandHeader) next.showTitle = instance.data.brandHeader.showTitle;
|
|
instance.setData({ brandHeader: next });
|
|
}
|
|
function clearNativeTitle(instance) {
|
|
if (!platform || typeof platform.setNavigationBar !== 'function') return;
|
|
var seq = instance.brandHeaderSeq = (instance.brandHeaderSeq || 0) + 1, settled = false;
|
|
function result(ok) {
|
|
if (settled) return; settled = true;
|
|
if (!instance.brandHeaderVisible || instance.brandHeaderSeq !== seq) return;
|
|
// The entry page can retain a platform-owned app name. If clearing is
|
|
// explicitly rejected, show one native title rather than two titles.
|
|
if (!ok && !options.nativeTitleFallback) return;
|
|
instance.setData({ brandHeader: Object.assign({}, instance.data.brandHeader, { showTitle: ok }) });
|
|
}
|
|
try {
|
|
var pending = platform.setNavigationBar({ title: '\u200b', success: function () { result(true); }, fail: function () { result(false); } });
|
|
if (pending && typeof pending.then === 'function') Promise.resolve(pending).then(function () { result(true); }, function () { result(false); });
|
|
} catch (_) { result(false); }
|
|
}
|
|
definition.onLoad = function () { this.brandHeaderVisible = true; refresh(this); clearNativeTitle(this); if (load) return load.apply(this, arguments); };
|
|
definition.onShow = function () { this.brandHeaderVisible = true; clearNativeTitle(this); if (show) return show.apply(this, arguments); };
|
|
definition.onReady = function () { clearNativeTitle(this); if (ready) return ready.apply(this, arguments); };
|
|
definition.onHide = function () { this.brandHeaderVisible = false; this.brandHeaderSeq = (this.brandHeaderSeq || 0) + 1; if (hide) return hide.apply(this, arguments); };
|
|
definition.onUnload = function () { this.brandHeaderVisible = false; this.brandHeaderSeq = (this.brandHeaderSeq || 0) + 1; if (unload) return unload.apply(this, arguments); };
|
|
definition.onResize = function () { refresh(this); if (resize) return resize.apply(this, arguments); };
|
|
return definition;
|
|
}
|
|
module.exports = { page: page, layout: layout };
|