Commit d2ee7c3f authored by 郑磊's avatar 郑磊

getStatusBar方法支持根据配置参数计算顶部状态栏高度

parent 759ebe4b
import { getCookie } from '../web/cookie' import { getCookie } from '../web/cookie'
export { type DeviceType, device, in_app, lang, open_source } from '../web/environment' export { type DeviceType, device, in_app, lang, open_source, run_methods } from '../web/environment'
/** /**
* 当前轻应用的appid * 当前轻应用的appid
......
...@@ -56,3 +56,13 @@ export const lang = normalizeLang(getCookie('lang') || navigator.language) ...@@ -56,3 +56,13 @@ export const lang = normalizeLang(getCookie('lang') || navigator.language)
* 当前页面的打开来源 * 当前页面的打开来源
*/ */
export const open_source = getCookie('open_source') || '' export const open_source = getCookie('open_source') || ''
/**
* 通过地址栏runmethod参数传递给页面的控制参数
*/
export const run_methods = (() => {
const url = new URL(location.href)
const methods = url.searchParams.get('runmethod')
if (!methods) return []
return methods.split('_')
})()
import { run_methods } from './environment'
import { callNativeApi, callNativeAsyncApi } from './native-api-base' import { callNativeApi, callNativeAsyncApi } from './native-api-base'
/** /**
...@@ -9,10 +10,32 @@ export function close() { ...@@ -9,10 +10,32 @@ export function close() {
} }
/** /**
* 获取状态栏高度 * 获取状态栏高度(会根据是否有顶部导航栏、是否半屏来自动判断)
* @returns * @returns
*/ */
export function getStatusBarHeight(): Promise<number> { export function getStatusBarHeight(): Promise<number> {
if (!run_methods.includes('hidetopbar')) {
//页面会显示导航栏,始终返回0
return Promise.resolve(0)
}
//尝试解析height参数,这是半屏显示
const height = new URL(location.href).searchParams.get('height')
if (height !== null) {
const numberHeight = parseInt(height)
if (!isNaN(numberHeight) && numberHeight > 0 && numberHeight < 100) {
//指定了半屏参数
return Promise.resolve(0)
}
}
return getStatusBarHeightRaw()
}
/**
* 获取原始的状态栏高度(不考虑半屏影响)
*/
export function getStatusBarHeightRaw(): Promise<number> {
console.log('调用框架方法', 'getStatusBarHeight') console.log('调用框架方法', 'getStatusBarHeight')
return new Promise<number>((resolve) => return new Promise<number>((resolve) =>
callNativeApi('getStatusBarHeight', (value: any) => { callNativeApi('getStatusBarHeight', (value: any) => {
......
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