@zero-bits/react-native-hot-update 1.0.0

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.
Files changed (54) hide show
  1. package/README.md +159 -0
  2. package/es/constants.d.ts +20 -0
  3. package/es/constants.js +20 -0
  4. package/es/index.d.ts +4 -0
  5. package/es/index.js +3 -0
  6. package/es/initialize.d.ts +14 -0
  7. package/es/initialize.js +32 -0
  8. package/es/updateProvider.d.ts +75 -0
  9. package/es/updateProvider.js +74 -0
  10. package/es/updateState.d.ts +25 -0
  11. package/es/updateState.js +166 -0
  12. package/es/usePushyUpdate.d.ts +17 -0
  13. package/es/usePushyUpdate.js +108 -0
  14. package/es/widget/animated.overlay.d.ts +12 -0
  15. package/es/widget/animated.overlay.js +96 -0
  16. package/es/widget/content.widget.d.ts +5 -0
  17. package/es/widget/content.widget.js +55 -0
  18. package/es/widget/description.widget.d.ts +5 -0
  19. package/es/widget/description.widget.js +33 -0
  20. package/es/widget/download.modal.widget.d.ts +5 -0
  21. package/es/widget/download.modal.widget.js +130 -0
  22. package/es/widget/footer.widget.d.ts +5 -0
  23. package/es/widget/footer.widget.js +153 -0
  24. package/es/widget/title.widget.d.ts +5 -0
  25. package/es/widget/title.widget.js +27 -0
  26. package/es/widget/update.modal.widget.d.ts +5 -0
  27. package/es/widget/update.modal.widget.js +50 -0
  28. package/lib/constants.d.ts +20 -0
  29. package/lib/constants.js +26 -0
  30. package/lib/index.d.ts +4 -0
  31. package/lib/index.js +36 -0
  32. package/lib/initialize.d.ts +14 -0
  33. package/lib/initialize.js +38 -0
  34. package/lib/updateProvider.d.ts +75 -0
  35. package/lib/updateProvider.js +83 -0
  36. package/lib/updateState.d.ts +25 -0
  37. package/lib/updateState.js +176 -0
  38. package/lib/usePushyUpdate.d.ts +17 -0
  39. package/lib/usePushyUpdate.js +114 -0
  40. package/lib/widget/animated.overlay.d.ts +12 -0
  41. package/lib/widget/animated.overlay.js +104 -0
  42. package/lib/widget/content.widget.d.ts +5 -0
  43. package/lib/widget/content.widget.js +63 -0
  44. package/lib/widget/description.widget.d.ts +5 -0
  45. package/lib/widget/description.widget.js +41 -0
  46. package/lib/widget/download.modal.widget.d.ts +5 -0
  47. package/lib/widget/download.modal.widget.js +138 -0
  48. package/lib/widget/footer.widget.d.ts +5 -0
  49. package/lib/widget/footer.widget.js +161 -0
  50. package/lib/widget/title.widget.d.ts +5 -0
  51. package/lib/widget/title.widget.js +35 -0
  52. package/lib/widget/update.modal.widget.d.ts +5 -0
  53. package/lib/widget/update.modal.widget.js +59 -0
  54. package/package.json +30 -0
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = usePushyUpdate;
8
+ var _react = require("react");
9
+ var _reactNativeUpdate = require("react-native-update");
10
+ var _updateState = require("./updateState");
11
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
12
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
14
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
18
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
+ /**
21
+ * @description 更新检查钩子
22
+ * @returns 更新检查钩子
23
+ */
24
+ function usePushyUpdate() {
25
+ var _useUpdate = (0, _reactNativeUpdate.useUpdate)(),
26
+ checkUpdate = _useUpdate.checkUpdate,
27
+ updateInfo = _useUpdate.updateInfo,
28
+ downloadUpdate = _useUpdate.downloadUpdate,
29
+ switchVersion = _useUpdate.switchVersion,
30
+ switchVersionLater = _useUpdate.switchVersionLater,
31
+ progress = _useUpdate.progress,
32
+ markSuccess = _useUpdate.markSuccess;
33
+ var _useUpdateState = (0, _updateState.useUpdateState)(),
34
+ showUpdateModal = _useUpdateState.showUpdateModal,
35
+ startDownloadFlow = _useUpdateState.startDownloadFlow;
36
+ var _useState = (0, _react.useState)(false),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ isChecking = _useState2[0],
39
+ setIsChecking = _useState2[1];
40
+ var _useState3 = (0, _react.useState)(null),
41
+ _useState4 = _slicedToArray(_useState3, 2),
42
+ error = _useState4[0],
43
+ setError = _useState4[1];
44
+
45
+ /**
46
+ * @description 检查更新
47
+ * @param flag false=静默检查(仅有更新时弹窗)/ true=手动触发(无论结果都弹窗)
48
+ * @returns 检查更新结果
49
+ */
50
+ function checkUpdateApp() {
51
+ return _checkUpdateApp.apply(this, arguments);
52
+ }
53
+ function _checkUpdateApp() {
54
+ _checkUpdateApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
55
+ var flag,
56
+ updateInfos,
57
+ hasValidInfo,
58
+ _args = arguments;
59
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
60
+ while (1) switch (_context.prev = _context.next) {
61
+ case 0:
62
+ flag = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
63
+ setIsChecking(true);
64
+ setError(null);
65
+ _context.prev = 3;
66
+ _context.next = 6;
67
+ return checkUpdate();
68
+ case 6:
69
+ updateInfos = _context.sent;
70
+ hasValidInfo = (updateInfos === null || updateInfos === void 0 ? void 0 : updateInfos.upToDate) || (updateInfos === null || updateInfos === void 0 ? void 0 : updateInfos.update) || (updateInfos === null || updateInfos === void 0 ? void 0 : updateInfos.expired);
71
+ if (hasValidInfo) {
72
+ _context.next = 10;
73
+ break;
74
+ }
75
+ return _context.abrupt("return", updateInfos);
76
+ case 10:
77
+ if (!(!flag && updateInfos !== null && updateInfos !== void 0 && updateInfos.upToDate)) {
78
+ _context.next = 12;
79
+ break;
80
+ }
81
+ return _context.abrupt("return", updateInfos);
82
+ case 12:
83
+ showUpdateModal();
84
+ return _context.abrupt("return", updateInfos);
85
+ case 16:
86
+ _context.prev = 16;
87
+ _context.t0 = _context["catch"](3);
88
+ console.warn('检查更新失败:', _context.t0);
89
+ setError(_context.t0);
90
+ case 20:
91
+ _context.prev = 20;
92
+ setIsChecking(false);
93
+ return _context.finish(20);
94
+ case 23:
95
+ case "end":
96
+ return _context.stop();
97
+ }
98
+ }, _callee, null, [[3, 16, 20, 23]]);
99
+ }));
100
+ return _checkUpdateApp.apply(this, arguments);
101
+ }
102
+ return {
103
+ checkUpdateApp: checkUpdateApp,
104
+ updateInfo: updateInfo,
105
+ isChecking: isChecking,
106
+ error: error,
107
+ startDownloadFlow: startDownloadFlow,
108
+ downloadUpdate: downloadUpdate,
109
+ switchVersion: switchVersion,
110
+ switchVersionLater: switchVersionLater,
111
+ progress: progress,
112
+ markSuccess: markSuccess
113
+ };
114
+ }
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ children?: React.ReactNode;
4
+ visible: boolean;
5
+ onAnimationComplete?: (visible: boolean) => void;
6
+ }
7
+ /**
8
+ * @description 动画弹窗原子组件
9
+ * @returns 动画弹窗原子组件
10
+ */
11
+ export default function AnimatedOverlay({ children, visible, onAnimationComplete }: Props): any;
12
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = AnimatedOverlay;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactNative = require("react-native");
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
16
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
18
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
22
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
+ /**
24
+ * @description 动画弹窗原子组件
25
+ * @returns 动画弹窗原子组件
26
+ */
27
+ function AnimatedOverlay(_ref) {
28
+ var children = _ref.children,
29
+ visible = _ref.visible,
30
+ onAnimationComplete = _ref.onAnimationComplete;
31
+ var _useState = (0, _react.useState)(visible),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ mounted = _useState2[0],
34
+ setMounted = _useState2[1];
35
+ var isComponentMounted = (0, _react.useRef)(true);
36
+ var opacity = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
37
+ var scale = (0, _react.useRef)(new _reactNative.Animated.Value(0.9)).current;
38
+ (0, _react.useEffect)(function () {
39
+ return function () {
40
+ isComponentMounted.current = false;
41
+ };
42
+ }, []);
43
+ (0, _react.useEffect)(function () {
44
+ if (visible) {
45
+ setMounted(true);
46
+ _reactNative.Animated.parallel([_reactNative.Animated.timing(opacity, {
47
+ toValue: 1,
48
+ duration: 250,
49
+ easing: _reactNative.Easing.out(_reactNative.Easing.ease),
50
+ useNativeDriver: true
51
+ }), _reactNative.Animated.spring(scale, {
52
+ toValue: 1,
53
+ friction: 8,
54
+ tension: 40,
55
+ useNativeDriver: true
56
+ })]).start(function () {
57
+ if (isComponentMounted.current) onAnimationComplete === null || onAnimationComplete === void 0 || onAnimationComplete(true);
58
+ });
59
+ } else {
60
+ _reactNative.Animated.parallel([_reactNative.Animated.timing(opacity, {
61
+ toValue: 0,
62
+ duration: 200,
63
+ easing: _reactNative.Easing.in(_reactNative.Easing.ease),
64
+ useNativeDriver: true
65
+ }), _reactNative.Animated.timing(scale, {
66
+ toValue: 0.9,
67
+ duration: 200,
68
+ easing: _reactNative.Easing.in(_reactNative.Easing.ease),
69
+ useNativeDriver: true
70
+ })]).start(function () {
71
+ if (isComponentMounted.current) {
72
+ setMounted(false);
73
+ onAnimationComplete === null || onAnimationComplete === void 0 || onAnimationComplete(false);
74
+ }
75
+ });
76
+ }
77
+ }, [visible]);
78
+ if (!mounted) return null;
79
+ return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
80
+ style: [Style.container, {
81
+ opacity: opacity
82
+ }]
83
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
84
+ style: [Style.contentWrapper, {
85
+ transform: [{
86
+ scale: scale
87
+ }]
88
+ }]
89
+ }, children));
90
+ }
91
+ var Style = _reactNative.StyleSheet.create({
92
+ container: _objectSpread(_objectSpread({
93
+ backgroundColor: 'rgba(0,0,0,.4)'
94
+ }, _reactNative.StyleSheet.absoluteFillObject), {}, {
95
+ justifyContent: 'center',
96
+ flexDirection: 'column',
97
+ elevation: 999,
98
+ zIndex: 999
99
+ }),
100
+ contentWrapper: {
101
+ justifyContent: 'center',
102
+ alignItems: 'center'
103
+ }
104
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description 更新内容原子组件
3
+ * @returns 更新内容原子组件
4
+ */
5
+ export default function ContentWidget(): any;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = ContentWidget;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactNative = require("react-native");
10
+ var _reactNativeUpdate = require("react-native-update");
11
+ var _updateProvider = require("../updateProvider");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ /**
15
+ * @description 更新内容原子组件
16
+ * @returns 更新内容原子组件
17
+ */
18
+ function ContentWidget() {
19
+ var _useUpdate = (0, _reactNativeUpdate.useUpdate)(),
20
+ updateInfo = _useUpdate.updateInfo;
21
+ var config = (0, _react.useContext)(_updateProvider.HotUpdateContext);
22
+ var primaryColor = config.themeColor || 'rgba(52,92,255,1)';
23
+ if (updateInfo !== null && updateInfo !== void 0 && updateInfo.upToDate) return null;
24
+ /**
25
+ * @description 解析更新内容
26
+ * @returns 更新内容
27
+ */
28
+ function parseDescription() {
29
+ try {
30
+ var _updateInfo$descripti;
31
+ if (!(updateInfo !== null && updateInfo !== void 0 && updateInfo.description)) return [];
32
+ var description = (_updateInfo$descripti = updateInfo.description) === null || _updateInfo$descripti === void 0 ? void 0 : _updateInfo$descripti.replace(/\\n/g, '\n');
33
+ return description.split('\n');
34
+ } catch (err) {}
35
+ return [(updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.description) || '修复应用bug'];
36
+ }
37
+ var messages = parseDescription();
38
+ return /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
39
+ style: Style.container,
40
+ contentContainerStyle: Style.contentContainer
41
+ }, messages.map(function (text, index) {
42
+ return /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
43
+ key: index,
44
+ style: [Style.text, {
45
+ color: primaryColor
46
+ }]
47
+ }, index + 1, ".", text);
48
+ }));
49
+ }
50
+ var Style = _reactNative.StyleSheet.create({
51
+ container: {
52
+ maxHeight: 250,
53
+ marginVertical: 10
54
+ },
55
+ contentContainer: {
56
+ paddingHorizontal: 20,
57
+ flexDirection: 'column'
58
+ },
59
+ text: {
60
+ fontSize: 14,
61
+ marginTop: 4
62
+ }
63
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description 更新提示原子组件
3
+ * @returns 更新提示原子组件
4
+ */
5
+ export default function DescriptWidget(): any;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = DescriptWidget;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactNative = require("react-native");
10
+ var _reactNativeUpdate = require("react-native-update");
11
+ var _updateProvider = require("../updateProvider");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ /**
15
+ * @description 更新提示原子组件
16
+ * @returns 更新提示原子组件
17
+ */
18
+ function DescriptWidget() {
19
+ var _useUpdate = (0, _reactNativeUpdate.useUpdate)(),
20
+ updateInfo = _useUpdate.updateInfo;
21
+ var config = (0, _react.useContext)(_updateProvider.HotUpdateContext);
22
+ var locale = config.localeText;
23
+ var description = '';
24
+ if (updateInfo !== null && updateInfo !== void 0 && updateInfo.expired) description = locale.updateExpired;else if (updateInfo !== null && updateInfo !== void 0 && updateInfo.upToDate) description = locale.updateUpToDate;else if (updateInfo !== null && updateInfo !== void 0 && updateInfo.update) description = "".concat(locale.updateAvailable, "\uFF0C\u7248\u672C\u53F7\u4E3A").concat(updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.name, "\uFF0C\u8BF7\u53CA\u65F6\u66F4\u65B0\uFF0C\u66F4\u65B0\u5185\u5BB9\u5982\u4E0B\uFF1A");
25
+ if (!description) return null;
26
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
27
+ style: Style.container
28
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
29
+ style: Style.title
30
+ }, description));
31
+ }
32
+ var Style = _reactNative.StyleSheet.create({
33
+ container: {
34
+ marginTop: 10,
35
+ paddingHorizontal: 20
36
+ },
37
+ title: {
38
+ fontSize: 14,
39
+ lineHeight: 20
40
+ }
41
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description 下载弹窗组件
3
+ * @returns 下载弹窗组件
4
+ */
5
+ export default function DownloadWidget(): any;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = DownloadWidget;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeUpdate = require("react-native-update");
10
+ var _updateProvider = require("../updateProvider");
11
+ var _updateState = require("../updateState");
12
+ var _animated = _interopRequireDefault(require("./animated.overlay"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
17
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
21
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
22
+ /**
23
+ * @description 下载弹窗组件
24
+ * @returns 下载弹窗组件
25
+ */
26
+ function DownloadWidget() {
27
+ var _useUpdate = (0, _reactNativeUpdate.useUpdate)(),
28
+ _useUpdate$progress = _useUpdate.progress,
29
+ _useUpdate$progress2 = _useUpdate$progress === void 0 ? {} : _useUpdate$progress,
30
+ _useUpdate$progress2$ = _useUpdate$progress2.received,
31
+ received = _useUpdate$progress2$ === void 0 ? 0 : _useUpdate$progress2$,
32
+ _useUpdate$progress2$2 = _useUpdate$progress2.total,
33
+ total = _useUpdate$progress2$2 === void 0 ? 0 : _useUpdate$progress2$2;
34
+ var _useUpdateState = (0, _updateState.useUpdateState)(),
35
+ isDownloadVisible = _useUpdateState.isDownloadVisible,
36
+ hideDownloadModal = _useUpdateState.hideDownloadModal;
37
+ var config = (0, _react.useContext)(_updateProvider.HotUpdateContext);
38
+ var locale = config.localeText;
39
+ var primaryColor = config.themeColor || 'rgba(52,92,255,1)';
40
+ var isStarted = total > 0;
41
+ var percent = isStarted ? Math.floor(received / total * 100) : 0;
42
+
43
+ /**
44
+ * @description 格式化字节
45
+ * @param bytes 字节数
46
+ * @returns 格式化后的字节数
47
+ */
48
+ var formatBytes = function formatBytes(bytes) {
49
+ if (bytes === 0) return '0 B';
50
+ var k = 1024;
51
+ var sizes = ['B', 'KB', 'MB', 'GB'];
52
+ var i = Math.floor(Math.log(bytes) / Math.log(k));
53
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
54
+ };
55
+ var content = null;
56
+ if (config.renderDownloadModal) {
57
+ content = config.renderDownloadModal({
58
+ received: received,
59
+ total: total
60
+ }, {
61
+ hideModal: hideDownloadModal
62
+ });
63
+ } else {
64
+ content = /*#__PURE__*/_react.default.createElement(_reactNative.View, {
65
+ style: Style.content
66
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
67
+ style: Style.header
68
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
69
+ style: Style.title
70
+ }, locale.downloadingTitle)), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
71
+ style: Style.progress
72
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
73
+ style: Style.progressTrack
74
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
75
+ style: _objectSpread(_objectSpread({}, Style.bar), {}, {
76
+ backgroundColor: primaryColor,
77
+ width: "".concat(percent, "%")
78
+ })
79
+ })), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
80
+ style: Style.gress
81
+ }, percent, "%")), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
82
+ style: Style.info
83
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
84
+ style: Style.recived
85
+ }, locale.downloadedBytes, formatBytes(received)), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
86
+ style: {
87
+ fontSize: 12
88
+ }
89
+ }, locale.totalBytes, formatBytes(total))));
90
+ }
91
+ return /*#__PURE__*/_react.default.createElement(_animated.default, {
92
+ visible: isDownloadVisible
93
+ }, content);
94
+ }
95
+ var Style = _reactNative.StyleSheet.create({
96
+ content: {
97
+ backgroundColor: 'white',
98
+ marginHorizontal: 20,
99
+ borderRadius: 8,
100
+ padding: 20,
101
+ flexDirection: 'column',
102
+ width: '90%',
103
+ maxWidth: 400
104
+ },
105
+ header: {
106
+ height: 30
107
+ },
108
+ title: {
109
+ fontSize: 16
110
+ },
111
+ progress: {
112
+ flexDirection: 'row',
113
+ alignItems: 'center'
114
+ },
115
+ progressTrack: {
116
+ flex: 1,
117
+ height: 10,
118
+ backgroundColor: '#eee',
119
+ borderRadius: 5,
120
+ flexDirection: 'row',
121
+ overflow: 'hidden'
122
+ },
123
+ bar: {
124
+ height: '100%'
125
+ },
126
+ gress: {
127
+ marginLeft: 10,
128
+ fontSize: 12
129
+ },
130
+ info: {
131
+ flexDirection: 'row',
132
+ marginTop: 10
133
+ },
134
+ recived: {
135
+ flex: 1,
136
+ fontSize: 12
137
+ }
138
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description 更新弹窗底部操作按钮组件
3
+ * @returns 更新弹窗底部操作按钮组件
4
+ */
5
+ export default function FooterWidget(): any;