@lemon-fe/mini-app 0.1.3 → 0.1.9

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.
@@ -30,6 +30,7 @@ import { parsePath } from '../../utils/path';
30
30
  import { NavigationContext } from '../../context';
31
31
  import Screen from '../Screen';
32
32
  import { GO_BACK } from '../../constants';
33
+ import { mini } from '../../global';
33
34
  import './index.css';
34
35
 
35
36
  function App(props) {
@@ -107,9 +108,7 @@ function App(props) {
107
108
  });
108
109
  }, []);
109
110
  useEffect(function () {
110
- var _window$mini;
111
-
112
- return (_window$mini = window.mini) === null || _window$mini === void 0 ? void 0 : _window$mini.addListener(function (e) {
111
+ return mini.addListener(function (e) {
113
112
  if (e === GO_BACK) {
114
113
  goBack();
115
114
  }
package/es/global.d.ts CHANGED
@@ -1,25 +1,4 @@
1
- declare global {
2
- interface Window {
3
- ReactNativeWebView?: {
4
- postMessage(e: string): void;
5
- };
6
- mini?: {
7
- getSystemInfoSync(): {
8
- statusBarHeight: number;
9
- pixelRatio: number;
10
- safeArea: {
11
- top: number;
12
- right: number;
13
- bottom: number;
14
- left: number;
15
- };
16
- };
17
- addListener(cb: (e: string) => void): void;
18
- getExtraPayload(): unknown;
19
- };
20
- }
21
- }
22
- export declare const mini: {
1
+ interface Mini {
23
2
  getSystemInfoSync(): {
24
3
  statusBarHeight: number;
25
4
  pixelRatio: number;
@@ -32,4 +11,15 @@ export declare const mini: {
32
11
  };
33
12
  addListener(cb: (e: string) => void): void;
34
13
  getExtraPayload(): unknown;
35
- };
14
+ }
15
+ declare global {
16
+ interface Window {
17
+ ReactNativeWebView?: {
18
+ postMessage(e: string): void;
19
+ };
20
+ mini?: Mini;
21
+ }
22
+ }
23
+ export declare let mini: Mini;
24
+ export declare function createApp(render: () => void): void;
25
+ export {};
package/es/global.js CHANGED
@@ -1,20 +1,36 @@
1
- if (window.mini === undefined) {
2
- window.mini = {
3
- getSystemInfoSync: function getSystemInfoSync() {
4
- return {
5
- statusBarHeight: 0,
6
- pixelRatio: window.devicePixelRatio,
7
- safeArea: {
8
- top: 0,
9
- right: 0,
10
- bottom: 0,
11
- left: 0
12
- }
13
- };
14
- },
15
- addListener: function addListener() {},
16
- getExtraPayload: function getExtraPayload() {}
1
+ export var mini = {
2
+ getSystemInfoSync: function getSystemInfoSync() {
3
+ return {
4
+ statusBarHeight: 0,
5
+ pixelRatio: window.devicePixelRatio,
6
+ safeArea: {
7
+ top: 0,
8
+ right: 0,
9
+ bottom: 0,
10
+ left: 0
11
+ }
12
+ };
13
+ },
14
+ addListener: function addListener() {},
15
+ getExtraPayload: function getExtraPayload() {}
16
+ };
17
+ export function createApp(render) {
18
+ var count = 0;
19
+
20
+ var check = function check() {
21
+ if (window.mini === undefined) {
22
+ count++;
23
+
24
+ if (count <= 10) {
25
+ setTimeout(check, 100);
26
+ } else {
27
+ render();
28
+ }
29
+ } else {
30
+ mini = window.mini;
31
+ render();
32
+ }
17
33
  };
18
- }
19
34
 
20
- export var mini = window.mini;
35
+ check();
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/mini-app",
3
- "version": "0.1.3",
3
+ "version": "0.1.9",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",