1 | import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
2 | import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
3 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4 | import { useEffect, useRef } from 'react';
|
5 | import raf from "rc-util/es/raf";
|
6 | import useState from "rc-util/es/hooks/useState";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var StatusQueue = ['measure', 'alignPre', 'align', null, 'motion'];
|
19 | export default (function (visible, doMeasure) {
|
20 | var _useState = useState(null),
|
21 | _useState2 = _slicedToArray(_useState, 2),
|
22 | status = _useState2[0],
|
23 | setInternalStatus = _useState2[1];
|
24 |
|
25 | var rafRef = useRef();
|
26 |
|
27 | function setStatus(nextStatus) {
|
28 | setInternalStatus(nextStatus, true);
|
29 | }
|
30 |
|
31 | function cancelRaf() {
|
32 | raf.cancel(rafRef.current);
|
33 | }
|
34 |
|
35 | function goNextStatus(callback) {
|
36 | cancelRaf();
|
37 | rafRef.current = raf(function () {
|
38 |
|
39 | setStatus(function (prev) {
|
40 | switch (status) {
|
41 | case 'align':
|
42 | return 'motion';
|
43 |
|
44 | case 'motion':
|
45 | return 'stable';
|
46 |
|
47 | default:
|
48 | }
|
49 |
|
50 | return prev;
|
51 | });
|
52 | callback === null || callback === void 0 ? void 0 : callback();
|
53 | });
|
54 | }
|
55 |
|
56 |
|
57 | useEffect(function () {
|
58 | setStatus('measure');
|
59 | }, [visible]);
|
60 |
|
61 | useEffect(function () {
|
62 | switch (status) {
|
63 | case 'measure':
|
64 | doMeasure();
|
65 | break;
|
66 |
|
67 | default:
|
68 | }
|
69 |
|
70 | if (status) {
|
71 | rafRef.current = raf( _asyncToGenerator( _regeneratorRuntime().mark(function _callee() {
|
72 | var index, nextStatus;
|
73 | return _regeneratorRuntime().wrap(function _callee$(_context) {
|
74 | while (1) {
|
75 | switch (_context.prev = _context.next) {
|
76 | case 0:
|
77 | index = StatusQueue.indexOf(status);
|
78 | nextStatus = StatusQueue[index + 1];
|
79 |
|
80 | if (nextStatus && index !== -1) {
|
81 | setStatus(nextStatus);
|
82 | }
|
83 |
|
84 | case 3:
|
85 | case "end":
|
86 | return _context.stop();
|
87 | }
|
88 | }
|
89 | }, _callee);
|
90 | })));
|
91 | }
|
92 | }, [status]);
|
93 | useEffect(function () {
|
94 | return function () {
|
95 | cancelRaf();
|
96 | };
|
97 | }, []);
|
98 | return [status, goNextStatus];
|
99 | }); |
\ | No newline at end of file |