@microbt/environment 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -160,6 +160,37 @@ console.log(versionInfo);
160
160
  // 在非 SuperAcme 应用中输出:{ version: "unknown" }
161
161
  ```
162
162
 
163
+ ### `getStatusBarHeight()`
164
+
165
+ 获取 SuperAcme 应用的状态栏高度信息。
166
+
167
+ **返回值**: 返回一个包含状态栏高度信息的对象:
168
+
169
+ ```json
170
+ {
171
+ top: number; // 顶部状态栏高度,单位为像素
172
+ bottom: number; // 底部状态栏高度,单位为像素
173
+ }
174
+ ```
175
+
176
+ 如果不在 SuperAcme 应用中或无法解析高度信息,将返回默认值:
177
+
178
+ ```json
179
+ {
180
+ "top": 0,
181
+ "bottom": 0
182
+ }
183
+ ```
184
+
185
+ **示例** :
186
+
187
+ ```typescript
188
+ const statusBarHeight = getStatusBarHeight();
189
+ console.log(statusBarHeight);
190
+ // 可能输出:{ top: 20, bottom: 0 }
191
+ // 在非 SuperAcme 应用中输出:{ top: 0, bottom: 0 }
192
+ ```
193
+
163
194
  ## 平台相关函数
164
195
 
165
196
  ### `iOSWebview`
@@ -9,3 +9,7 @@ export declare function superAcmeVersion(): {
9
9
  minor: number;
10
10
  patch: number;
11
11
  };
12
+ export declare function getStatusBarHeight(): {
13
+ top: number;
14
+ bottom: number;
15
+ };
@@ -75,6 +75,8 @@ function inSuperAcme() {
75
75
  return navigator.userAgent.toLowerCase().includes("superacme");
76
76
  }
77
77
  var VERSION_REGEX = /AppVersion\s([\d.]+)/;
78
+ var STATUSBAR_TOP_REGEX = /statusBarTop:([\d.]+)/;
79
+ var STATUSBAR_BOTTOM_REGEX = /statusBarBottom:([\d.]+)/;
78
80
  function superAcmeVersion() {
79
81
  const ua = navigator.userAgent;
80
82
  const UNKNOWN = {
@@ -96,9 +98,26 @@ function superAcmeVersion() {
96
98
  }
97
99
  return UNKNOWN;
98
100
  }
101
+ function getStatusBarHeight() {
102
+ const ua = navigator.userAgent;
103
+ const DEFAULT_HEIGHT = {
104
+ top: 0,
105
+ bottom: 0
106
+ };
107
+ if (!inSuperAcme()) {
108
+ return DEFAULT_HEIGHT;
109
+ }
110
+ const topMatch = ua.match(STATUSBAR_TOP_REGEX);
111
+ const bottomMatch = ua.match(STATUSBAR_BOTTOM_REGEX);
112
+ return {
113
+ top: topMatch ? parseFloat(topMatch[1]) : DEFAULT_HEIGHT.top,
114
+ bottom: bottomMatch ? parseFloat(bottomMatch[1]) : DEFAULT_HEIGHT.bottom
115
+ };
116
+ }
99
117
  export {
100
118
  bridgeBootstrap,
101
119
  bridgeCall,
120
+ getStatusBarHeight,
102
121
  inSuperAcme,
103
122
  superAcmeVersion
104
123
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microbt/environment",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "microbt app library for environment",
5
5
  "keywords": [],
6
6
  "license": "MIT",