@tecsinapse/react-native-kit 1.12.1 → 1.12.5
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/CHANGELOG.md +32 -0
- package/dist/components/atoms/Modal/ModalGroupManager.d.ts +3 -0
- package/dist/components/atoms/Modal/ModalGroupManager.js +37 -0
- package/dist/components/atoms/Modal/ModalGroupManager.js.map +1 -0
- package/dist/components/atoms/Modal/ModalLifecycleHandler.d.ts +23 -0
- package/dist/components/atoms/Modal/ModalLifecycleHandler.js +109 -0
- package/dist/components/atoms/Modal/ModalLifecycleHandler.js.map +1 -0
- package/dist/components/atoms/Modal/index.d.ts +5 -0
- package/dist/components/atoms/Modal/index.js +71 -0
- package/dist/components/atoms/Modal/index.js.map +1 -0
- package/dist/components/atoms/Modal/ui/BaseModalView.d.ts +3 -0
- package/dist/components/atoms/Modal/ui/BaseModalView.js +103 -0
- package/dist/components/atoms/Modal/ui/BaseModalView.js.map +1 -0
- package/dist/components/atoms/Modal/ui/styled.d.ts +6 -0
- package/dist/components/atoms/Modal/ui/styled.js +35 -0
- package/dist/components/atoms/Modal/ui/styled.js.map +1 -0
- package/dist/components/atoms/Modal/ui/types.d.ts +7 -0
- package/dist/components/atoms/Modal/ui/types.js +6 -0
- package/dist/components/atoms/Modal/ui/types.js.map +1 -0
- package/dist/components/atoms/Modal/useModalManager.d.ts +6 -0
- package/dist/components/atoms/Modal/useModalManager.js +35 -0
- package/dist/components/atoms/Modal/useModalManager.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +38 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/src/components/atoms/Modal/ModalGroupManager.tsx +28 -0
- package/src/components/atoms/Modal/ModalLifecycleHandler.ts +139 -0
- package/src/components/atoms/Modal/index.ts +5 -0
- package/src/components/atoms/Modal/ui/BaseModalView.tsx +88 -0
- package/src/components/atoms/Modal/ui/styled.ts +22 -0
- package/src/components/atoms/Modal/ui/types.ts +10 -0
- package/src/components/atoms/Modal/useModalManager.ts +35 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.12.5](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.12.4...@tecsinapse/react-native-kit@1.12.5) (2021-12-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @tecsinapse/react-native-kit
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.12.4](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.12.3...@tecsinapse/react-native-kit@1.12.4) (2021-12-23)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @tecsinapse/react-native-kit
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [1.12.3](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.12.2...@tecsinapse/react-native-kit@1.12.3) (2021-12-23)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @tecsinapse/react-native-kit
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [1.12.2](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.12.1...@tecsinapse/react-native-kit@1.12.2) (2021-12-22)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @tecsinapse/react-native-kit
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [1.12.1](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-native-kit@1.12.0...@tecsinapse/react-native-kit@1.12.1) (2021-12-21)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package @tecsinapse/react-native-kit
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ModalGroupManager = exports.modalLifecycle = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _ModalLifecycleHandler = require("./ModalLifecycleHandler");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
|
|
18
|
+
const modalLifecycle = (0, _ModalLifecycleHandler.createModalLifecycleHandler)();
|
|
19
|
+
exports.modalLifecycle = modalLifecycle;
|
|
20
|
+
|
|
21
|
+
const ModalGroupManager = ({
|
|
22
|
+
children
|
|
23
|
+
}) => {
|
|
24
|
+
modalLifecycle.attach((0, _react.useState)([]));
|
|
25
|
+
|
|
26
|
+
const _render = modalLifecycle.render();
|
|
27
|
+
|
|
28
|
+
const hasModals = _render.length > 0;
|
|
29
|
+
return _react.default.createElement(_react.default.Fragment, null, children, _react.default.createElement(_reactNative.Modal, {
|
|
30
|
+
visible: hasModals,
|
|
31
|
+
transparent: true,
|
|
32
|
+
animationType: "none"
|
|
33
|
+
}, _render));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.ModalGroupManager = ModalGroupManager;
|
|
37
|
+
//# sourceMappingURL=ModalGroupManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/atoms/Modal/ModalGroupManager.tsx"],"names":["modalLifecycle","ModalGroupManager","children","attach","_render","render","hasModals","length"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;AAGO,MAAMA,cAAc,GAAG,yDAAvB;;;AAQA,MAAMC,iBAAqB,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAkB;AAEnDF,EAAAA,cAAc,CAACG,MAAf,CAAsB,qBAAqC,EAArC,CAAtB;;AACA,QAAMC,OAAO,GAAGJ,cAAc,CAACK,MAAf,EAAhB;;AACA,QAAMC,SAAS,GAAGF,OAAO,CAACG,MAAR,GAAiB,CAAnC;AAEA,SACI,4DACKL,QADL,EAEI,6BAAC,kBAAD;AAAS,IAAA,OAAO,EAAEI,SAAlB;AAA6B,IAAA,WAAW,MAAxC;AAAyC,IAAA,aAAa,EAAC;AAAvD,KACKF,OADL,CAFJ,CADJ;AAQH,CAdM","sourcesContent":["import React, { FC, ReactElement, useState } from 'react';\nimport { Modal as RNModal } from 'react-native';\nimport { createModalLifecycleHandler } from './ModalLifecycleHandler';\nimport { IBaseModal } from './ui/types';\n\nexport const modalLifecycle = createModalLifecycleHandler()\n\n/**\n * It's responsable for rendering all the modal components.\n * \n * @param param0 \n * @returns \n */\nexport const ModalGroupManager: FC = ({ children }) => {\n\n modalLifecycle.attach(useState<ReactElement<IBaseModal>[]>([]))\n const _render = modalLifecycle.render()\n const hasModals = _render.length > 0\n \n return (\n <>\n {children}\n <RNModal visible={hasModals} transparent animationType='none'>\n {_render}\n </RNModal>\n </>\n )\n}\n"],"file":"ModalGroupManager.js"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dispatch, ReactElement } from "react";
|
|
2
|
+
import { IBaseModal } from "./ui/types";
|
|
3
|
+
interface ModalNode {
|
|
4
|
+
id: string;
|
|
5
|
+
visible?: boolean;
|
|
6
|
+
lastVisualization?: Date;
|
|
7
|
+
modal: () => ReactElement<IBaseModal>;
|
|
8
|
+
}
|
|
9
|
+
export declare class ModalLifecycleHandler {
|
|
10
|
+
nodeGroup: Map<string, ModalNode>;
|
|
11
|
+
state: [ReactElement<IBaseModal>[], Dispatch<ReactElement<IBaseModal>[]>] | undefined;
|
|
12
|
+
constructor();
|
|
13
|
+
attach: (state: [ReactElement<IBaseModal>[], Dispatch<ReactElement<IBaseModal>[]>]) => void;
|
|
14
|
+
update: () => void;
|
|
15
|
+
render: () => ReactElement<IBaseModal>[];
|
|
16
|
+
sync: (id: string, modal: () => ReactElement<IBaseModal>) => void;
|
|
17
|
+
destroy: (id: string) => void;
|
|
18
|
+
private remove;
|
|
19
|
+
show: (id: string) => void;
|
|
20
|
+
close: (id: string) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const createModalLifecycleHandler: () => ModalLifecycleHandler;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createModalLifecycleHandler = exports.ModalLifecycleHandler = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
class ModalLifecycleHandler {
|
|
15
|
+
constructor() {
|
|
16
|
+
_defineProperty(this, "attach", state => {
|
|
17
|
+
this.state = state;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "update", () => {
|
|
21
|
+
const nodes = Array.from(this.nodeGroup.values()).filter(node => node.visible || !!node.lastVisualization).sort((nodeA, nodeB) => {
|
|
22
|
+
var _nodeA$lastVisualizat, _nodeB$lastVisualizat;
|
|
23
|
+
|
|
24
|
+
return (((_nodeA$lastVisualizat = nodeA.lastVisualization) === null || _nodeA$lastVisualizat === void 0 ? void 0 : _nodeA$lastVisualizat.getTime()) || 0) - (((_nodeB$lastVisualizat = nodeB.lastVisualization) === null || _nodeB$lastVisualizat === void 0 ? void 0 : _nodeB$lastVisualizat.getTime()) || 0);
|
|
25
|
+
}).map(node => {
|
|
26
|
+
let modalElement = node.modal();
|
|
27
|
+
let {
|
|
28
|
+
props
|
|
29
|
+
} = modalElement;
|
|
30
|
+
return _react.default.cloneElement(modalElement, {
|
|
31
|
+
key: node.id,
|
|
32
|
+
visible: node.visible,
|
|
33
|
+
close: () => this.close(node.id),
|
|
34
|
+
onClose: () => {
|
|
35
|
+
var _props$onClose;
|
|
36
|
+
|
|
37
|
+
this.remove(node.id);
|
|
38
|
+
(_props$onClose = props.onClose) === null || _props$onClose === void 0 ? void 0 : _props$onClose.call(props);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const [, updateState] = this.state || [];
|
|
43
|
+
updateState === null || updateState === void 0 ? void 0 : updateState(nodes);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
_defineProperty(this, "render", () => {
|
|
47
|
+
const [modals] = this.state || [];
|
|
48
|
+
return modals || [];
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
_defineProperty(this, "sync", (id, modal) => {
|
|
52
|
+
if (this.nodeGroup.has(id)) {
|
|
53
|
+
const savedNode = this.nodeGroup.get(id);
|
|
54
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode,
|
|
55
|
+
modal
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.nodeGroup.set(id, {
|
|
61
|
+
id,
|
|
62
|
+
modal
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
_defineProperty(this, "destroy", id => {
|
|
67
|
+
this.nodeGroup.delete(id);
|
|
68
|
+
this.update();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
_defineProperty(this, "remove", id => {
|
|
72
|
+
const savedNode = this.nodeGroup.get(id);
|
|
73
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode,
|
|
74
|
+
lastVisualization: undefined
|
|
75
|
+
});
|
|
76
|
+
this.update();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
_defineProperty(this, "show", id => {
|
|
80
|
+
const savedNode = this.nodeGroup.get(id);
|
|
81
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode,
|
|
82
|
+
visible: true,
|
|
83
|
+
lastVisualization: new Date()
|
|
84
|
+
});
|
|
85
|
+
this.update();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
_defineProperty(this, "close", id => {
|
|
89
|
+
const savedNode = this.nodeGroup.get(id);
|
|
90
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode,
|
|
91
|
+
visible: false
|
|
92
|
+
});
|
|
93
|
+
this.update();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.nodeGroup = new Map();
|
|
97
|
+
this.state = undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.ModalLifecycleHandler = ModalLifecycleHandler;
|
|
103
|
+
|
|
104
|
+
const createModalLifecycleHandler = () => {
|
|
105
|
+
return new ModalLifecycleHandler();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
exports.createModalLifecycleHandler = createModalLifecycleHandler;
|
|
109
|
+
//# sourceMappingURL=ModalLifecycleHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/atoms/Modal/ModalLifecycleHandler.ts"],"names":["ModalLifecycleHandler","constructor","state","nodes","Array","from","nodeGroup","values","filter","node","visible","lastVisualization","sort","nodeA","nodeB","getTime","map","modalElement","modal","props","React","cloneElement","key","id","close","onClose","remove","updateState","modals","has","savedNode","get","set","delete","update","undefined","Date","Map","createModalLifecycleHandler"],"mappings":"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","sourcesContent":["import React, { Dispatch, ReactElement } from \"react\"\nimport { IBaseModal } from \"./ui/types\"\n\n/**\n * It Represents a node (usually a modal component) in the modal's lifecycle handler.\n */\ninterface ModalNode {\n id: string\n visible?: boolean\n lastVisualization?: Date\n modal: () => ReactElement<IBaseModal>\n}\n\n/**\n * Manage all modal's lifecycle.\n */\nexport class ModalLifecycleHandler {\n \n nodeGroup: Map<string, ModalNode>\n state: [ReactElement<IBaseModal>[], Dispatch<ReactElement<IBaseModal>[]>] | undefined\n\n constructor() {\n this.nodeGroup = new Map()\n this.state = undefined\n }\n\n /**\n * Holds the ModalGroupManager state.\n * \n * @param state \n */\n public attach = (state: [ReactElement<IBaseModal>[], Dispatch<ReactElement<IBaseModal>[]>]) => {\n this.state = state\n }\n\n /**\n * Updates all the modal components.\n */\n public update = () => {\n const nodes = Array.from(this.nodeGroup.values())\n .filter(node => node.visible || !!node.lastVisualization)\n .sort((nodeA, nodeB) => (nodeA.lastVisualization?.getTime() || 0) - (nodeB.lastVisualization?.getTime() || 0))\n .map(node => {\n let modalElement = node.modal()\n let { props } = modalElement\n return React.cloneElement(modalElement, {\n key: node.id,\n visible: node.visible,\n close: () => this.close(node.id),\n onClose: () => {\n this.remove(node.id)\n props.onClose?.()\n }\n })\n })\n \n const [, updateState ] = this.state || []\n updateState?.(nodes)\n }\n\n /**\n * Renders all selected modals.\n * \n * @returns \n */\n public render = (): ReactElement<IBaseModal>[] => {\n const [ modals ] = this.state || []\n return modals || []\n }\n\n /**\n * Tells to the lifecycle handler that a modal component needs to be handled.\n * \n * @param id \n * @param modal \n * @returns \n */\n public sync = (id: string, modal: () => ReactElement<IBaseModal>) => {\n if (this.nodeGroup.has(id)) {\n const savedNode = this.nodeGroup.get(id)\n savedNode && this.nodeGroup.set(id, { ...savedNode, modal })\n return\n }\n this.nodeGroup.set(id, { id, modal })\n }\n\n /**\n * Destroy a modal from the lifecycle handler.\n * \n * @param id \n */\n public destroy = (id: string) => {\n this.nodeGroup.delete(id)\n this.update()\n }\n\n /**\n * Removes a modal from the rendering stack. It tells to the lifecycle handler that a modal \n * component is no longer used by the application.\n * \n * @param id \n */\n private remove = (id: string) => {\n const savedNode = this.nodeGroup.get(id)\n savedNode && this.nodeGroup.set(id, { ...savedNode, lastVisualization: undefined })\n this.update()\n }\n\n /**\n * Makes a modal appears.\n * \n * @param id \n */\n public show = (id: string) => {\n const savedNode = this.nodeGroup.get(id)\n savedNode && this.nodeGroup.set(id, { ...savedNode, visible: true, lastVisualization: new Date() })\n this.update()\n }\n\n /**\n * Makes a modal disappears.\n * \n * @param id \n */\n public close = (id: string) => {\n const savedNode = this.nodeGroup.get(id)\n savedNode && this.nodeGroup.set(id, { ...savedNode, visible: false })\n this.update()\n }\n}\n\n/**\n * Creates a new ModalLifecycleHandlere instance.\n * \n * @returns \n */\nexport const createModalLifecycleHandler = () => {\n return new ModalLifecycleHandler()\n}\n"],"file":"ModalLifecycleHandler.js"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _ModalGroupManager = require("./ModalGroupManager");
|
|
8
|
+
|
|
9
|
+
Object.keys(_ModalGroupManager).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _ModalGroupManager[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _ModalGroupManager[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _ModalLifecycleHandler = require("./ModalLifecycleHandler");
|
|
21
|
+
|
|
22
|
+
Object.keys(_ModalLifecycleHandler).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _ModalLifecycleHandler[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _ModalLifecycleHandler[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _BaseModalView = require("./ui/BaseModalView");
|
|
34
|
+
|
|
35
|
+
Object.keys(_BaseModalView).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _BaseModalView[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _BaseModalView[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _types = require("./ui/types");
|
|
47
|
+
|
|
48
|
+
Object.keys(_types).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _types[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
var _useModalManager = require("./useModalManager");
|
|
60
|
+
|
|
61
|
+
Object.keys(_useModalManager).forEach(function (key) {
|
|
62
|
+
if (key === "default" || key === "__esModule") return;
|
|
63
|
+
if (key in exports && exports[key] === _useModalManager[key]) return;
|
|
64
|
+
Object.defineProperty(exports, key, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _useModalManager[key];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/atoms/Modal/index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './ModalGroupManager'\nexport * from './ModalLifecycleHandler'\nexport * from './ui/BaseModalView'\nexport * from './ui/types'\nexport * from './useModalManager'"],"file":"index.js"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ModalView = void 0;
|
|
7
|
+
|
|
8
|
+
var _reactCore = require("@tecsinapse/react-core");
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _reactNative = require("react-native");
|
|
13
|
+
|
|
14
|
+
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
|
|
15
|
+
|
|
16
|
+
var _styled = require("./styled");
|
|
17
|
+
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
const BACKDROP_ALPHA = .65;
|
|
23
|
+
const INTERPOLATION_STEPS = 10;
|
|
24
|
+
const INTERPOLATION_DURATION = 195;
|
|
25
|
+
|
|
26
|
+
const ModalView = ({
|
|
27
|
+
children,
|
|
28
|
+
visible,
|
|
29
|
+
BoxComponent = _reactCore.BoxContent,
|
|
30
|
+
close,
|
|
31
|
+
onClose
|
|
32
|
+
}) => {
|
|
33
|
+
const {
|
|
34
|
+
bottom
|
|
35
|
+
} = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
|
|
36
|
+
const {
|
|
37
|
+
height
|
|
38
|
+
} = (0, _reactNative.useWindowDimensions)();
|
|
39
|
+
const backgroundCarrier = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
|
|
40
|
+
const translationCarrier = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
|
|
41
|
+
const show = (0, _react.useCallback)(to => {
|
|
42
|
+
_reactNative.Animated.sequence([_reactNative.Animated.timing(backgroundCarrier, {
|
|
43
|
+
toValue: INTERPOLATION_STEPS,
|
|
44
|
+
duration: INTERPOLATION_DURATION,
|
|
45
|
+
easing: _reactNative.Easing.out(_reactNative.Easing.circle),
|
|
46
|
+
useNativeDriver: false
|
|
47
|
+
}), _reactNative.Animated.timing(translationCarrier, {
|
|
48
|
+
toValue: to,
|
|
49
|
+
duration: INTERPOLATION_DURATION,
|
|
50
|
+
easing: _reactNative.Easing.out(_reactNative.Easing.circle),
|
|
51
|
+
useNativeDriver: true
|
|
52
|
+
})]).start();
|
|
53
|
+
}, []);
|
|
54
|
+
const hide = (0, _react.useCallback)(() => {
|
|
55
|
+
_reactNative.Animated.sequence([_reactNative.Animated.timing(translationCarrier, {
|
|
56
|
+
toValue: 0,
|
|
57
|
+
duration: INTERPOLATION_DURATION,
|
|
58
|
+
easing: _reactNative.Easing.out(_reactNative.Easing.circle),
|
|
59
|
+
useNativeDriver: true
|
|
60
|
+
}), _reactNative.Animated.timing(backgroundCarrier, {
|
|
61
|
+
toValue: 0,
|
|
62
|
+
duration: INTERPOLATION_DURATION,
|
|
63
|
+
easing: _reactNative.Easing.out(_reactNative.Easing.circle),
|
|
64
|
+
useNativeDriver: false
|
|
65
|
+
})]).start(onClose);
|
|
66
|
+
}, [onClose]);
|
|
67
|
+
const backgroundInterpolation = backgroundCarrier.interpolate({
|
|
68
|
+
inputRange: [0, INTERPOLATION_STEPS],
|
|
69
|
+
outputRange: ['rgba(0, 0, 0, 0)', `rgba(0, 0, 0, ${BACKDROP_ALPHA})`]
|
|
70
|
+
});
|
|
71
|
+
const handleBoxLayoutChanges = (0, _react.useCallback)(lce => {
|
|
72
|
+
let boxHeight = lce.nativeEvent.layout.height;
|
|
73
|
+
boxHeight > 0 && show(-(boxHeight + bottom));
|
|
74
|
+
}, [show]);
|
|
75
|
+
(0, _react.useEffect)(() => {
|
|
76
|
+
if (!visible) {
|
|
77
|
+
hide();
|
|
78
|
+
}
|
|
79
|
+
}, [visible]);
|
|
80
|
+
return _react.default.createElement(_styled.StyledPressableBackDrop, {
|
|
81
|
+
onPress: close
|
|
82
|
+
}, _react.default.createElement(_styled.BackDropView, {
|
|
83
|
+
height: height,
|
|
84
|
+
style: {
|
|
85
|
+
backgroundColor: backgroundInterpolation
|
|
86
|
+
}
|
|
87
|
+
}), _react.default.createElement(_reactNative.Animated.View, {
|
|
88
|
+
style: {
|
|
89
|
+
transform: [{
|
|
90
|
+
translateY: translationCarrier
|
|
91
|
+
}]
|
|
92
|
+
}
|
|
93
|
+
}, _react.default.createElement(_reactNative.Pressable, null, _react.default.createElement(BoxComponent, {
|
|
94
|
+
onLayout: handleBoxLayoutChanges,
|
|
95
|
+
style: {
|
|
96
|
+
paddingBottom: bottom
|
|
97
|
+
},
|
|
98
|
+
variant: "bottom"
|
|
99
|
+
}, _react.default.createElement(_styled.CloseBar, null), children))));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.ModalView = ModalView;
|
|
103
|
+
//# sourceMappingURL=BaseModalView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/atoms/Modal/ui/BaseModalView.tsx"],"names":["BACKDROP_ALPHA","INTERPOLATION_STEPS","INTERPOLATION_DURATION","ModalView","children","visible","BoxComponent","BoxContent","close","onClose","bottom","height","backgroundCarrier","Animated","Value","current","translationCarrier","show","to","sequence","timing","toValue","duration","easing","Easing","out","circle","useNativeDriver","start","hide","backgroundInterpolation","interpolate","inputRange","outputRange","handleBoxLayoutChanges","lce","boxHeight","nativeEvent","layout","backgroundColor","transform","translateY","paddingBottom"],"mappings":"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","sourcesContent":["import { BoxContent } from \"@tecsinapse/react-core\";\nimport React, { FC, useCallback, useEffect, useRef } from \"react\";\nimport { Animated, Easing, LayoutChangeEvent, Pressable, useWindowDimensions } from \"react-native\";\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { BackDropView, CloseBar, StyledPressableBackDrop } from \"./styled\";\nimport { IBaseModal } from \"./types\";\n\nconst BACKDROP_ALPHA = .65\nconst INTERPOLATION_STEPS = 10\nconst INTERPOLATION_DURATION = 195 //ms\n\nexport const ModalView: FC<IBaseModal> = ({ \n children,\n visible,\n BoxComponent = BoxContent,\n close,\n onClose\n}) => {\n \n const { bottom } = useSafeAreaInsets()\n const { height } = useWindowDimensions()\n const backgroundCarrier = useRef(new Animated.Value(0)).current\n const translationCarrier = useRef(new Animated.Value(0)).current\n\n const show = useCallback((to: number) => {\n Animated.sequence([\n Animated.timing(backgroundCarrier, {\n toValue: INTERPOLATION_STEPS,\n duration: INTERPOLATION_DURATION,\n easing: Easing.out(Easing.circle),\n useNativeDriver: false\n }),\n Animated.timing(translationCarrier, {\n toValue: to,\n duration: INTERPOLATION_DURATION,\n easing: Easing.out(Easing.circle),\n useNativeDriver: true\n })\n ]).start()\n }, [])\n\n const hide = useCallback(() => {\n Animated.sequence([\n Animated.timing(translationCarrier, {\n toValue: 0,\n duration: INTERPOLATION_DURATION,\n easing: Easing.out(Easing.circle),\n useNativeDriver: true\n }),\n Animated.timing(backgroundCarrier, {\n toValue: 0,\n duration: INTERPOLATION_DURATION,\n easing: Easing.out(Easing.circle),\n useNativeDriver: false\n })\n ]).start(onClose)\n }, [onClose])\n\n const backgroundInterpolation = backgroundCarrier.interpolate({\n inputRange: [0, INTERPOLATION_STEPS],\n outputRange: ['rgba(0, 0, 0, 0)', `rgba(0, 0, 0, ${BACKDROP_ALPHA})`]\n })\n\n const handleBoxLayoutChanges = useCallback((lce: LayoutChangeEvent) => {\n let boxHeight = lce.nativeEvent.layout.height\n boxHeight > 0 && show(-(boxHeight + bottom))\n }, [show])\n\n useEffect(() => {\n if (!visible) {\n hide()\n }\n }, [visible])\n\n return (\n <StyledPressableBackDrop onPress={close}>\n <BackDropView height={height} style={{ backgroundColor: backgroundInterpolation }}/>\n <Animated.View style={{ transform: [{ translateY: translationCarrier }]}}>\n <Pressable>\n <BoxComponent onLayout={handleBoxLayoutChanges} style={{ paddingBottom: bottom }} variant=\"bottom\">\n <CloseBar/>\n {children}\n </BoxComponent>\n </Pressable>\n </Animated.View>\n </StyledPressableBackDrop>\n )\n}"],"file":"BaseModalView.js"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const StyledPressableBackDrop: import("@emotion/native").StyledComponent<any, {}, {}>;
|
|
3
|
+
export declare const BackDropView: import("@emotion/native").StyledComponent<any, {}, {}>;
|
|
4
|
+
export declare const CloseBar: import("@emotion/native").StyledComponent<any, {}, {
|
|
5
|
+
ref?: import("react").Ref<import("react-native").View> | undefined;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CloseBar = exports.BackDropView = exports.StyledPressableBackDrop = void 0;
|
|
7
|
+
|
|
8
|
+
var _native = _interopRequireDefault(require("@emotion/native"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const StyledPressableBackDrop = _native.default.Pressable`
|
|
15
|
+
flex: 1;
|
|
16
|
+
position: absolute;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
`;
|
|
20
|
+
exports.StyledPressableBackDrop = StyledPressableBackDrop;
|
|
21
|
+
const BackDropView = (0, _native.default)(_reactNative.Animated.View)`
|
|
22
|
+
height: 100%;
|
|
23
|
+
`;
|
|
24
|
+
exports.BackDropView = BackDropView;
|
|
25
|
+
const CloseBar = _native.default.View`
|
|
26
|
+
background-color: ${({
|
|
27
|
+
theme
|
|
28
|
+
}) => theme.color.secondary.light};
|
|
29
|
+
border-radius: 10px;
|
|
30
|
+
margin: 5px auto;
|
|
31
|
+
width: 42px;
|
|
32
|
+
height: 5px;
|
|
33
|
+
`;
|
|
34
|
+
exports.CloseBar = CloseBar;
|
|
35
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/atoms/Modal/ui/styled.ts"],"names":["StyledPressableBackDrop","styled","Pressable","BackDropView","Animated","View","CloseBar","theme","color","secondary","light"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAEO,MAAMA,uBAAuB,GAAGC,gBAAOC,SAA+B;AAC7E;AACA;AACA;AACA;AACA,CALO;;AAOA,MAAMC,YAAY,GAAG,qBAAOC,sBAASC,IAAhB,CAAgE;AAC5F;AACA,CAFO;;AAIA,MAAMC,QAAQ,GAAGL,gBAAOI,IAA0B;AACzD,wBAAwB,CAAC;AAAEE,EAAAA;AAAF,CAAD,KAAeA,KAAK,CAACC,KAAN,CAAYC,SAAZ,CAAsBC,KAAM;AACnE;AACA;AACA;AACA;AACA,CANO","sourcesContent":["import styled from \"@emotion/native\";\nimport { StyleProps } from \"@tecsinapse/react-core\";\nimport { Animated } from \"react-native\";\n\nexport const StyledPressableBackDrop = styled.Pressable<Partial<StyleProps>>`\n flex: 1;\n position: absolute;\n width: 100%;\n height: 100%;\n`\n\nexport const BackDropView = styled(Animated.View)<{ height: number } & Partial<StyleProps>>`\n height: 100%;\n`\n\nexport const CloseBar = styled.View<Partial<StyleProps>>`\n background-color: ${({ theme }) => theme.color.secondary.light};\n border-radius: 10px;\n margin: 5px auto;\n width: 42px;\n height: 5px;\n`"],"file":"styled.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useModalManager = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _uuid = require("uuid");
|
|
11
|
+
|
|
12
|
+
var _ModalGroupManager = require("./ModalGroupManager");
|
|
13
|
+
|
|
14
|
+
const useModalManager = modal => {
|
|
15
|
+
const [id] = (0, _react.useState)((0, _uuid.v4)());
|
|
16
|
+
|
|
17
|
+
_ModalGroupManager.modalLifecycle.sync(id, modal);
|
|
18
|
+
|
|
19
|
+
const show = (0, _react.useCallback)(() => {
|
|
20
|
+
_ModalGroupManager.modalLifecycle.show(id);
|
|
21
|
+
}, [id]);
|
|
22
|
+
const close = (0, _react.useCallback)(() => {
|
|
23
|
+
_ModalGroupManager.modalLifecycle.close(id);
|
|
24
|
+
}, [id]);
|
|
25
|
+
(0, _react.useEffect)(() => {
|
|
26
|
+
return () => _ModalGroupManager.modalLifecycle.destroy(id);
|
|
27
|
+
}, []);
|
|
28
|
+
return {
|
|
29
|
+
show,
|
|
30
|
+
close
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useModalManager = useModalManager;
|
|
35
|
+
//# sourceMappingURL=useModalManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/atoms/Modal/useModalManager.ts"],"names":["useModalManager","modal","id","modalLifecycle","sync","show","close","destroy"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAWO,MAAMA,eAAe,GAAIC,KAAD,IAA2C;AAEtE,QAAM,CAACC,EAAD,IAAO,qBAAS,eAAT,CAAb;;AACAC,oCAAeC,IAAf,CAAoBF,EAApB,EAAwBD,KAAxB;;AAEA,QAAMI,IAAI,GAAG,wBAAY,MAAM;AAC3BF,sCAAeE,IAAf,CAAoBH,EAApB;AACH,GAFY,EAEV,CAACA,EAAD,CAFU,CAAb;AAIA,QAAMI,KAAK,GAAG,wBAAY,MAAM;AAC5BH,sCAAeG,KAAf,CAAqBJ,EAArB;AACH,GAFa,EAEX,CAACA,EAAD,CAFW,CAAd;AAIA,wBAAU,MAAM;AACZ,WAAO,MAAMC,kCAAeI,OAAf,CAAuBL,EAAvB,CAAb;AACH,GAFD,EAEG,EAFH;AAIA,SAAO;AACHG,IAAAA,IADG;AAEHC,IAAAA;AAFG,GAAP;AAIH,CArBM","sourcesContent":["import { ReactElement, useCallback, useEffect, useState } from \"react\"\nimport { v4 as uuidv4 } from 'uuid'\nimport { modalLifecycle } from \"./ModalGroupManager\"\nimport { IBaseModal } from \"./ui/types\"\n\n/**\n * Use this hook to tell the modal lifecycle handler that you want to add\n * a new modal component. \n * \n * @param id \n * @param modal \n * @returns\n */\nexport const useModalManager = (modal: () => ReactElement<IBaseModal>) => {\n\n const [id] = useState(uuidv4())\n modalLifecycle.sync(id, modal)\n\n const show = useCallback(() => {\n modalLifecycle.show(id)\n }, [id])\n\n const close = useCallback(() => {\n modalLifecycle.close(id)\n }, [id])\n \n useEffect(() => {\n return () => modalLifecycle.destroy(id)\n }, [])\n\n return {\n show,\n close\n }\n}"],"file":"useModalManager.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,4 @@ export { DateTimePicker } from './components/molecules/DateTimePicker';
|
|
|
17
17
|
export { Avatar } from './components/atoms/Avatar';
|
|
18
18
|
export { Calendar } from './components/molecules/Calendar';
|
|
19
19
|
export { DateTimeSelector } from './components/molecules/DateTimeSelector';
|
|
20
|
+
export { ModalGroupManager, ModalView, ModalLifecycleHandler, useModalManager, IBaseModal } from './components/atoms/Modal';
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,12 @@ var _exportNames = {
|
|
|
36
36
|
DateTimePicker: true,
|
|
37
37
|
Avatar: true,
|
|
38
38
|
Calendar: true,
|
|
39
|
-
DateTimeSelector: true
|
|
39
|
+
DateTimeSelector: true,
|
|
40
|
+
ModalGroupManager: true,
|
|
41
|
+
ModalView: true,
|
|
42
|
+
ModalLifecycleHandler: true,
|
|
43
|
+
useModalManager: true,
|
|
44
|
+
IBaseModal: true
|
|
40
45
|
};
|
|
41
46
|
Object.defineProperty(exports, "Header", {
|
|
42
47
|
enumerable: true,
|
|
@@ -236,6 +241,36 @@ Object.defineProperty(exports, "DateTimeSelector", {
|
|
|
236
241
|
return _DateTimeSelector.DateTimeSelector;
|
|
237
242
|
}
|
|
238
243
|
});
|
|
244
|
+
Object.defineProperty(exports, "ModalGroupManager", {
|
|
245
|
+
enumerable: true,
|
|
246
|
+
get: function () {
|
|
247
|
+
return _Modal.ModalGroupManager;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
Object.defineProperty(exports, "ModalView", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
get: function () {
|
|
253
|
+
return _Modal.ModalView;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
Object.defineProperty(exports, "ModalLifecycleHandler", {
|
|
257
|
+
enumerable: true,
|
|
258
|
+
get: function () {
|
|
259
|
+
return _Modal.ModalLifecycleHandler;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
Object.defineProperty(exports, "useModalManager", {
|
|
263
|
+
enumerable: true,
|
|
264
|
+
get: function () {
|
|
265
|
+
return _Modal.useModalManager;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
Object.defineProperty(exports, "IBaseModal", {
|
|
269
|
+
enumerable: true,
|
|
270
|
+
get: function () {
|
|
271
|
+
return _Modal.IBaseModal;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
239
274
|
|
|
240
275
|
var _reactCore = require("@tecsinapse/react-core");
|
|
241
276
|
|
|
@@ -286,4 +321,6 @@ var _Avatar = require("./components/atoms/Avatar");
|
|
|
286
321
|
var _Calendar = require("./components/molecules/Calendar");
|
|
287
322
|
|
|
288
323
|
var _DateTimeSelector = require("./components/molecules/DateTimeSelector");
|
|
324
|
+
|
|
325
|
+
var _Modal = require("./components/atoms/Modal");
|
|
289
326
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIA;;AAIA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["export * from '@tecsinapse/react-core';\nexport { Header, HeaderProps } from './components/atoms/Header';\nexport { Select, SelectNativeProps } from './components/atoms/Select';\nexport { Input, InputNativeProps } from './components/atoms/Input';\nexport { TextArea, TextAreaProps } from './components/atoms/TextArea';\nexport { Text, TextNativeProps } from './components/atoms/Text';\nexport { Error, Loading, Success, Button, ButtonNativeProps } from './components/atoms/Button';\nexport { GroupButtonOption } from './components/atoms/GroupButton';\nexport {\n InputPassword,\n InputPasswordNativeProps,\n} from './components/molecules/InputPassword';\nexport {\n BottomNavigator,\n BottomNavigatorProps,\n} from './components/atoms/BottomNavigator';\nexport { Tag, TagProps } from './components/atoms/Tag';\nexport {\n SnappingSlider,\n SnappingSliderProps,\n} from './components/atoms/SnappingSlider';\nexport { Badge, BadgeNativeProps } from './components/atoms/Badge';\nexport { Snackbar, SnackbarNativeProps } from './components/molecules/Snackbar';\nexport { DatePicker } from './components/molecules/DatePicker';\nexport { DateTimePicker } from './components/molecules/DateTimePicker';\nexport { Avatar } from './components/atoms/Avatar';\nexport { Calendar } from './components/molecules/Calendar';\nexport { DateTimeSelector } from './components/molecules/DateTimeSelector';\nexport { ModalGroupManager, ModalView, ModalLifecycleHandler, useModalManager, IBaseModal } from './components/atoms/Modal';\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/react-native-kit",
|
|
3
3
|
"description": "TecSinapse React Native components",
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.5",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@emotion/native": "^11.0.0",
|
|
15
15
|
"@emotion/react": "^11.4.1",
|
|
16
|
-
"@tecsinapse/react-core": "^1.12.
|
|
16
|
+
"@tecsinapse/react-core": "^1.12.4"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -27,7 +27,12 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=16.8.0",
|
|
29
29
|
"react-native": ">=0.64.0",
|
|
30
|
-
"react-native-
|
|
30
|
+
"react-native-safe-area-context": "^3.1.9",
|
|
31
|
+
"react-native-vector-icons": ">=8.1.0",
|
|
32
|
+
"uuid": "^8.3.2"
|
|
31
33
|
},
|
|
32
|
-
"
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/uuid": "^8.3.3"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "e7ef239d9f82576d17b344065a97d2136a165f64"
|
|
33
38
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { FC, ReactElement, useState } from 'react';
|
|
2
|
+
import { Modal as RNModal } from 'react-native';
|
|
3
|
+
import { createModalLifecycleHandler } from './ModalLifecycleHandler';
|
|
4
|
+
import { IBaseModal } from './ui/types';
|
|
5
|
+
|
|
6
|
+
export const modalLifecycle = createModalLifecycleHandler()
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* It's responsable for rendering all the modal components.
|
|
10
|
+
*
|
|
11
|
+
* @param param0
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export const ModalGroupManager: FC = ({ children }) => {
|
|
15
|
+
|
|
16
|
+
modalLifecycle.attach(useState<ReactElement<IBaseModal>[]>([]))
|
|
17
|
+
const _render = modalLifecycle.render()
|
|
18
|
+
const hasModals = _render.length > 0
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
{children}
|
|
23
|
+
<RNModal visible={hasModals} transparent animationType='none'>
|
|
24
|
+
{_render}
|
|
25
|
+
</RNModal>
|
|
26
|
+
</>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React, { Dispatch, ReactElement } from "react"
|
|
2
|
+
import { IBaseModal } from "./ui/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* It Represents a node (usually a modal component) in the modal's lifecycle handler.
|
|
6
|
+
*/
|
|
7
|
+
interface ModalNode {
|
|
8
|
+
id: string
|
|
9
|
+
visible?: boolean
|
|
10
|
+
lastVisualization?: Date
|
|
11
|
+
modal: () => ReactElement<IBaseModal>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Manage all modal's lifecycle.
|
|
16
|
+
*/
|
|
17
|
+
export class ModalLifecycleHandler {
|
|
18
|
+
|
|
19
|
+
nodeGroup: Map<string, ModalNode>
|
|
20
|
+
state: [ReactElement<IBaseModal>[], Dispatch<ReactElement<IBaseModal>[]>] | undefined
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.nodeGroup = new Map()
|
|
24
|
+
this.state = undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Holds the ModalGroupManager state.
|
|
29
|
+
*
|
|
30
|
+
* @param state
|
|
31
|
+
*/
|
|
32
|
+
public attach = (state: [ReactElement<IBaseModal>[], Dispatch<ReactElement<IBaseModal>[]>]) => {
|
|
33
|
+
this.state = state
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Updates all the modal components.
|
|
38
|
+
*/
|
|
39
|
+
public update = () => {
|
|
40
|
+
const nodes = Array.from(this.nodeGroup.values())
|
|
41
|
+
.filter(node => node.visible || !!node.lastVisualization)
|
|
42
|
+
.sort((nodeA, nodeB) => (nodeA.lastVisualization?.getTime() || 0) - (nodeB.lastVisualization?.getTime() || 0))
|
|
43
|
+
.map(node => {
|
|
44
|
+
let modalElement = node.modal()
|
|
45
|
+
let { props } = modalElement
|
|
46
|
+
return React.cloneElement(modalElement, {
|
|
47
|
+
key: node.id,
|
|
48
|
+
visible: node.visible,
|
|
49
|
+
close: () => this.close(node.id),
|
|
50
|
+
onClose: () => {
|
|
51
|
+
this.remove(node.id)
|
|
52
|
+
props.onClose?.()
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const [, updateState ] = this.state || []
|
|
58
|
+
updateState?.(nodes)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Renders all selected modals.
|
|
63
|
+
*
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
public render = (): ReactElement<IBaseModal>[] => {
|
|
67
|
+
const [ modals ] = this.state || []
|
|
68
|
+
return modals || []
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Tells to the lifecycle handler that a modal component needs to be handled.
|
|
73
|
+
*
|
|
74
|
+
* @param id
|
|
75
|
+
* @param modal
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
public sync = (id: string, modal: () => ReactElement<IBaseModal>) => {
|
|
79
|
+
if (this.nodeGroup.has(id)) {
|
|
80
|
+
const savedNode = this.nodeGroup.get(id)
|
|
81
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode, modal })
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
this.nodeGroup.set(id, { id, modal })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Destroy a modal from the lifecycle handler.
|
|
89
|
+
*
|
|
90
|
+
* @param id
|
|
91
|
+
*/
|
|
92
|
+
public destroy = (id: string) => {
|
|
93
|
+
this.nodeGroup.delete(id)
|
|
94
|
+
this.update()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Removes a modal from the rendering stack. It tells to the lifecycle handler that a modal
|
|
99
|
+
* component is no longer used by the application.
|
|
100
|
+
*
|
|
101
|
+
* @param id
|
|
102
|
+
*/
|
|
103
|
+
private remove = (id: string) => {
|
|
104
|
+
const savedNode = this.nodeGroup.get(id)
|
|
105
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode, lastVisualization: undefined })
|
|
106
|
+
this.update()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Makes a modal appears.
|
|
111
|
+
*
|
|
112
|
+
* @param id
|
|
113
|
+
*/
|
|
114
|
+
public show = (id: string) => {
|
|
115
|
+
const savedNode = this.nodeGroup.get(id)
|
|
116
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode, visible: true, lastVisualization: new Date() })
|
|
117
|
+
this.update()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Makes a modal disappears.
|
|
122
|
+
*
|
|
123
|
+
* @param id
|
|
124
|
+
*/
|
|
125
|
+
public close = (id: string) => {
|
|
126
|
+
const savedNode = this.nodeGroup.get(id)
|
|
127
|
+
savedNode && this.nodeGroup.set(id, { ...savedNode, visible: false })
|
|
128
|
+
this.update()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a new ModalLifecycleHandlere instance.
|
|
134
|
+
*
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
export const createModalLifecycleHandler = () => {
|
|
138
|
+
return new ModalLifecycleHandler()
|
|
139
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BoxContent } from "@tecsinapse/react-core";
|
|
2
|
+
import React, { FC, useCallback, useEffect, useRef } from "react";
|
|
3
|
+
import { Animated, Easing, LayoutChangeEvent, Pressable, useWindowDimensions } from "react-native";
|
|
4
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
|
+
import { BackDropView, CloseBar, StyledPressableBackDrop } from "./styled";
|
|
6
|
+
import { IBaseModal } from "./types";
|
|
7
|
+
|
|
8
|
+
const BACKDROP_ALPHA = .65
|
|
9
|
+
const INTERPOLATION_STEPS = 10
|
|
10
|
+
const INTERPOLATION_DURATION = 195 //ms
|
|
11
|
+
|
|
12
|
+
export const ModalView: FC<IBaseModal> = ({
|
|
13
|
+
children,
|
|
14
|
+
visible,
|
|
15
|
+
BoxComponent = BoxContent,
|
|
16
|
+
close,
|
|
17
|
+
onClose
|
|
18
|
+
}) => {
|
|
19
|
+
|
|
20
|
+
const { bottom } = useSafeAreaInsets()
|
|
21
|
+
const { height } = useWindowDimensions()
|
|
22
|
+
const backgroundCarrier = useRef(new Animated.Value(0)).current
|
|
23
|
+
const translationCarrier = useRef(new Animated.Value(0)).current
|
|
24
|
+
|
|
25
|
+
const show = useCallback((to: number) => {
|
|
26
|
+
Animated.sequence([
|
|
27
|
+
Animated.timing(backgroundCarrier, {
|
|
28
|
+
toValue: INTERPOLATION_STEPS,
|
|
29
|
+
duration: INTERPOLATION_DURATION,
|
|
30
|
+
easing: Easing.out(Easing.circle),
|
|
31
|
+
useNativeDriver: false
|
|
32
|
+
}),
|
|
33
|
+
Animated.timing(translationCarrier, {
|
|
34
|
+
toValue: to,
|
|
35
|
+
duration: INTERPOLATION_DURATION,
|
|
36
|
+
easing: Easing.out(Easing.circle),
|
|
37
|
+
useNativeDriver: true
|
|
38
|
+
})
|
|
39
|
+
]).start()
|
|
40
|
+
}, [])
|
|
41
|
+
|
|
42
|
+
const hide = useCallback(() => {
|
|
43
|
+
Animated.sequence([
|
|
44
|
+
Animated.timing(translationCarrier, {
|
|
45
|
+
toValue: 0,
|
|
46
|
+
duration: INTERPOLATION_DURATION,
|
|
47
|
+
easing: Easing.out(Easing.circle),
|
|
48
|
+
useNativeDriver: true
|
|
49
|
+
}),
|
|
50
|
+
Animated.timing(backgroundCarrier, {
|
|
51
|
+
toValue: 0,
|
|
52
|
+
duration: INTERPOLATION_DURATION,
|
|
53
|
+
easing: Easing.out(Easing.circle),
|
|
54
|
+
useNativeDriver: false
|
|
55
|
+
})
|
|
56
|
+
]).start(onClose)
|
|
57
|
+
}, [onClose])
|
|
58
|
+
|
|
59
|
+
const backgroundInterpolation = backgroundCarrier.interpolate({
|
|
60
|
+
inputRange: [0, INTERPOLATION_STEPS],
|
|
61
|
+
outputRange: ['rgba(0, 0, 0, 0)', `rgba(0, 0, 0, ${BACKDROP_ALPHA})`]
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const handleBoxLayoutChanges = useCallback((lce: LayoutChangeEvent) => {
|
|
65
|
+
let boxHeight = lce.nativeEvent.layout.height
|
|
66
|
+
boxHeight > 0 && show(-(boxHeight + bottom))
|
|
67
|
+
}, [show])
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!visible) {
|
|
71
|
+
hide()
|
|
72
|
+
}
|
|
73
|
+
}, [visible])
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<StyledPressableBackDrop onPress={close}>
|
|
77
|
+
<BackDropView height={height} style={{ backgroundColor: backgroundInterpolation }}/>
|
|
78
|
+
<Animated.View style={{ transform: [{ translateY: translationCarrier }]}}>
|
|
79
|
+
<Pressable>
|
|
80
|
+
<BoxComponent onLayout={handleBoxLayoutChanges} style={{ paddingBottom: bottom }} variant="bottom">
|
|
81
|
+
<CloseBar/>
|
|
82
|
+
{children}
|
|
83
|
+
</BoxComponent>
|
|
84
|
+
</Pressable>
|
|
85
|
+
</Animated.View>
|
|
86
|
+
</StyledPressableBackDrop>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import styled from "@emotion/native";
|
|
2
|
+
import { StyleProps } from "@tecsinapse/react-core";
|
|
3
|
+
import { Animated } from "react-native";
|
|
4
|
+
|
|
5
|
+
export const StyledPressableBackDrop = styled.Pressable<Partial<StyleProps>>`
|
|
6
|
+
flex: 1;
|
|
7
|
+
position: absolute;
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
export const BackDropView = styled(Animated.View)<{ height: number } & Partial<StyleProps>>`
|
|
13
|
+
height: 100%;
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
export const CloseBar = styled.View<Partial<StyleProps>>`
|
|
17
|
+
background-color: ${({ theme }) => theme.color.secondary.light};
|
|
18
|
+
border-radius: 10px;
|
|
19
|
+
margin: 5px auto;
|
|
20
|
+
width: 42px;
|
|
21
|
+
height: 5px;
|
|
22
|
+
`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ReactElement, useCallback, useEffect, useState } from "react"
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
3
|
+
import { modalLifecycle } from "./ModalGroupManager"
|
|
4
|
+
import { IBaseModal } from "./ui/types"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Use this hook to tell the modal lifecycle handler that you want to add
|
|
8
|
+
* a new modal component.
|
|
9
|
+
*
|
|
10
|
+
* @param id
|
|
11
|
+
* @param modal
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export const useModalManager = (modal: () => ReactElement<IBaseModal>) => {
|
|
15
|
+
|
|
16
|
+
const [id] = useState(uuidv4())
|
|
17
|
+
modalLifecycle.sync(id, modal)
|
|
18
|
+
|
|
19
|
+
const show = useCallback(() => {
|
|
20
|
+
modalLifecycle.show(id)
|
|
21
|
+
}, [id])
|
|
22
|
+
|
|
23
|
+
const close = useCallback(() => {
|
|
24
|
+
modalLifecycle.close(id)
|
|
25
|
+
}, [id])
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
return () => modalLifecycle.destroy(id)
|
|
29
|
+
}, [])
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
show,
|
|
33
|
+
close
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -26,3 +26,4 @@ export { DateTimePicker } from './components/molecules/DateTimePicker';
|
|
|
26
26
|
export { Avatar } from './components/atoms/Avatar';
|
|
27
27
|
export { Calendar } from './components/molecules/Calendar';
|
|
28
28
|
export { DateTimeSelector } from './components/molecules/DateTimeSelector';
|
|
29
|
+
export { ModalGroupManager, ModalView, ModalLifecycleHandler, useModalManager, IBaseModal } from './components/atoms/Modal';
|