@lemon-fe/mini-app 0.1.9 → 0.1.25

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.
@@ -1,9 +1,10 @@
1
- import { ReactElement } from 'react';
1
+ import { CSSProperties, ReactElement } from 'react';
2
2
  import type { NavigationStackScreen } from '../../typings';
3
3
  import './index.css';
4
4
  interface Props {
5
5
  pages: NavigationStackScreen[];
6
6
  children?: ReactElement | null;
7
+ headerStyle?: CSSProperties;
7
8
  }
8
9
  declare function App(props: Props): JSX.Element;
9
10
  export default App;
@@ -35,7 +35,8 @@ import './index.css';
35
35
 
36
36
  function App(props) {
37
37
  var pages = props.pages,
38
- children = props.children;
38
+ children = props.children,
39
+ headerStyle = props.headerStyle;
39
40
 
40
41
  var _useState = useState({
41
42
  routes: [{
@@ -92,8 +93,6 @@ function App(props) {
92
93
  }, []);
93
94
  var goBack = useCallback(function () {
94
95
  setState(function (prev) {
95
- var _window$ReactNativeWe;
96
-
97
96
  var nextRoutes = _toConsumableArray(prev.routes);
98
97
 
99
98
  if (nextRoutes.length > 1) {
@@ -103,7 +102,7 @@ function App(props) {
103
102
  });
104
103
  }
105
104
 
106
- (_window$ReactNativeWe = window.ReactNativeWebView) === null || _window$ReactNativeWe === void 0 ? void 0 : _window$ReactNativeWe.postMessage(GO_BACK);
105
+ mini.exit();
107
106
  return prev;
108
107
  });
109
108
  }, []);
@@ -119,9 +118,10 @@ function App(props) {
119
118
  navigation: {
120
119
  navigate: navigate,
121
120
  goBack: goBack
122
- }
121
+ },
122
+ headerStyle: headerStyle
123
123
  };
124
- }, [navigate, goBack]);
124
+ }, [navigate, goBack, headerStyle]);
125
125
  var screens = /*#__PURE__*/React.createElement(TransitionGroup, {
126
126
  className: "lemon-routes"
127
127
  }, state.routes.map(function (item, index) {
@@ -1,28 +1,32 @@
1
1
  .lemon-route {
2
- display: flex;
3
- flex-direction: column;
4
2
  position: absolute;
5
3
  top: 0;
6
4
  right: 0;
7
5
  bottom: 0;
8
- left: 0;
9
- background-color: #fff;
6
+ left: 0;
7
+ display: flex;
8
+ flex-direction: column;
10
9
  color: #333;
10
+ background-color: #fff;
11
11
  transition: transform 300ms;
12
12
  }
13
13
 
14
+ .lemon-route-header {
15
+ padding-top: env(safe-area-inset-top);
16
+ }
17
+
14
18
  .lemon-route-header-content {
15
19
  position: relative;
16
20
  height: 44px;
17
21
  }
18
22
 
19
23
  .lemon-route-header-left {
20
- display: flex;
21
- align-items: center;
22
24
  position: absolute;
23
25
  top: 0;
24
26
  bottom: 0;
25
27
  left: 0;
28
+ display: flex;
29
+ align-items: center;
26
30
  padding-left: 15px;
27
31
  line-height: 1;
28
32
  }
@@ -30,8 +34,8 @@
30
34
  .lemon-route-header-center {
31
35
  font-weight: bold;
32
36
  font-size: 16px;
33
- text-align: center;
34
37
  line-height: 44px;
38
+ text-align: center;
35
39
  }
36
40
 
37
41
  .lemon-route-body {
@@ -4,9 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import React, { createElement, memo, useMemo } from 'react';
8
- import { ScreenContext } from '../../context';
9
- import { useNavigation } from '../../hooks';
7
+ import React, { createElement, memo, useContext, useMemo } from 'react';
8
+ import { NavigationContext, ScreenContext } from '../../context';
10
9
  import { mini } from '../../global';
11
10
  import './index.css';
12
11
 
@@ -22,16 +21,20 @@ function Screen(props) {
22
21
  var statusBarHeight = useMemo(function () {
23
22
  return mini.getSystemInfoSync().statusBarHeight;
24
23
  }, []);
25
- var navigation = useNavigation();
24
+
25
+ var _useContext = useContext(NavigationContext),
26
+ navigation = _useContext.navigation,
27
+ headerStyle = _useContext.headerStyle;
28
+
26
29
  return /*#__PURE__*/React.createElement(ScreenContext.Provider, {
27
30
  value: ctx
28
31
  }, /*#__PURE__*/React.createElement("div", {
29
32
  className: "lemon-route"
30
33
  }, /*#__PURE__*/React.createElement("div", {
31
34
  className: "lemon-route-header",
32
- style: _objectSpread({
35
+ style: _objectSpread(_objectSpread({
33
36
  paddingTop: statusBarHeight
34
- }, route.headerStyle)
37
+ }, headerStyle), route.headerStyle)
35
38
  }, /*#__PURE__*/React.createElement("div", {
36
39
  className: "lemon-route-header-content"
37
40
  }, index > 0 && /*#__PURE__*/React.createElement("div", {
@@ -1,8 +1,10 @@
1
+ import type { CSSProperties } from 'react';
1
2
  export declare const NavigationContext: import("react").Context<{
2
3
  navigation: {
3
4
  navigate: (path: string, params?: Record<string, any> | undefined) => void;
4
5
  goBack: () => void;
5
6
  };
7
+ headerStyle?: CSSProperties | undefined;
6
8
  }>;
7
9
  export declare const ScreenContext: import("react").Context<{
8
10
  params?: Record<string, any> | undefined;
package/es/global.d.ts CHANGED
@@ -11,6 +11,14 @@ interface Mini {
11
11
  };
12
12
  addListener(cb: (e: string) => void): void;
13
13
  getExtraPayload(): unknown;
14
+ scanCode(opts: {
15
+ success: (value: string) => void;
16
+ }): void;
17
+ setStatusBarStyle(opt: {
18
+ success?: () => void;
19
+ params: 'default' | 'light-content' | 'dark-content';
20
+ }): void;
21
+ exit(): void;
14
22
  }
15
23
  declare global {
16
24
  interface Window {
package/es/global.js CHANGED
@@ -12,7 +12,10 @@ export var mini = {
12
12
  };
13
13
  },
14
14
  addListener: function addListener() {},
15
- getExtraPayload: function getExtraPayload() {}
15
+ getExtraPayload: function getExtraPayload() {},
16
+ scanCode: function scanCode() {},
17
+ exit: function exit() {},
18
+ setStatusBarStyle: function setStatusBarStyle() {}
16
19
  };
17
20
  export function createApp(render) {
18
21
  var count = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/mini-app",
3
- "version": "0.1.9",
3
+ "version": "0.1.25",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -27,9 +27,12 @@
27
27
  "react-transition-group": "^4.4.2"
28
28
  },
29
29
  "peerDependencies": {
30
+ "color-string": "^1.6.0",
30
31
  "react": ">=17.0.2"
31
32
  },
32
33
  "devDependencies": {
33
- "@types/react-transition-group": "^4.4.4"
34
- }
34
+ "@types/react-transition-group": "^4.4.4",
35
+ "color-string": "^1.9.0"
36
+ },
37
+ "gitHead": "ea6abf747e0deb1b7f8bdf638639800206b59b42"
35
38
  }