@mpxjs/webpack-plugin 2.10.4-beta.19-input → 2.10.4-beta.19-input1
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/lib/runtime/components/react/dist/getInnerListeners.js +22 -36
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +4 -2
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +17 -20
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-image.jsx +20 -33
- package/lib/runtime/components/react/dist/mpx-input.jsx +9 -14
- package/lib/runtime/components/react/dist/mpx-label.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +3 -8
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +79 -205
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +13 -11
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +7 -8
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +11 -29
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -9
- package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -10
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +51 -104
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +1 -3
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +9 -11
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +141 -203
- package/lib/runtime/components/react/dist/mpx-switch.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-text.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-video.jsx +2 -7
- package/lib/runtime/components/react/dist/mpx-view.jsx +26 -28
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +29 -34
- package/lib/runtime/components/react/dist/useAnimationHooks.js +89 -12
- package/lib/runtime/components/react/dist/utils.jsx +114 -199
- package/package.json +1 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +0 -145
- package/lib/runtime/components/react/dist/mpx-progress.jsx +0 -163
- package/lib/runtime/components/react/dist/mpx-slider.jsx +0 -321
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement
|
|
1
|
+
import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
3
|
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils';
|
|
4
4
|
import { VarContext, ScrollViewContext, RouteContext } from './context';
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
7
7
|
import FastImage from '@d11/react-native-fast-image';
|
|
8
|
+
import { runOnJS } from 'react-native-reanimated';
|
|
8
9
|
import { Gesture } from 'react-native-gesture-handler';
|
|
9
10
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
10
11
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
@@ -25,7 +26,6 @@ const unoVarDecRegExp = /^--un-/;
|
|
|
25
26
|
const unoVarUseRegExp = /var\(--un-/;
|
|
26
27
|
const calcUseRegExp = /calc\(/;
|
|
27
28
|
const envUseRegExp = /env\(/;
|
|
28
|
-
const filterRegExp = /(calc|env|%)/;
|
|
29
29
|
const safeAreaInsetMap = {
|
|
30
30
|
'safe-area-inset-top': 'top',
|
|
31
31
|
'safe-area-inset-right': 'right',
|
|
@@ -121,8 +121,6 @@ const selfPercentRule = {
|
|
|
121
121
|
};
|
|
122
122
|
const parentHeightPercentRule = {
|
|
123
123
|
height: true,
|
|
124
|
-
minHeight: true,
|
|
125
|
-
maxHeight: true,
|
|
126
124
|
top: true,
|
|
127
125
|
bottom: true
|
|
128
126
|
};
|
|
@@ -183,11 +181,10 @@ function resolveVar(input, varContext) {
|
|
|
183
181
|
});
|
|
184
182
|
return global.__formatValue(replaced.source());
|
|
185
183
|
}
|
|
186
|
-
function transformVar(styleObj, varKeyPaths, varContext
|
|
184
|
+
function transformVar(styleObj, varKeyPaths, varContext) {
|
|
187
185
|
varKeyPaths.forEach((varKeyPath) => {
|
|
188
186
|
setStyle(styleObj, varKeyPath, ({ target, key, value }) => {
|
|
189
187
|
target[key] = resolveVar(value, varContext);
|
|
190
|
-
visitOther({ target, key, value: target[key], keyPath: varKeyPath });
|
|
191
188
|
});
|
|
192
189
|
});
|
|
193
190
|
}
|
|
@@ -227,122 +224,28 @@ function transformCalc(styleObj, calcKeyPaths, formatter) {
|
|
|
227
224
|
});
|
|
228
225
|
});
|
|
229
226
|
}
|
|
227
|
+
const stringifyProps = ['fontWeight'];
|
|
230
228
|
function transformStringify(styleObj) {
|
|
231
|
-
|
|
232
|
-
styleObj
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
function transformPosition(styleObj, meta) {
|
|
236
|
-
if (styleObj.position === 'fixed') {
|
|
237
|
-
styleObj.position = 'absolute';
|
|
238
|
-
meta.hasPositionFixed = true;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// 多value解析
|
|
242
|
-
function parseValues(str, char = ' ') {
|
|
243
|
-
let stack = 0;
|
|
244
|
-
let temp = '';
|
|
245
|
-
const result = [];
|
|
246
|
-
for (let i = 0; i < str.length; i++) {
|
|
247
|
-
if (str[i] === '(') {
|
|
248
|
-
stack++;
|
|
249
|
-
}
|
|
250
|
-
else if (str[i] === ')') {
|
|
251
|
-
stack--;
|
|
252
|
-
}
|
|
253
|
-
// 非括号内 或者 非分隔字符且非空
|
|
254
|
-
if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
|
|
255
|
-
temp += str[i];
|
|
256
|
-
}
|
|
257
|
-
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
|
|
258
|
-
result.push(temp);
|
|
259
|
-
temp = '';
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
265
|
-
function parseTransform(transformStr) {
|
|
266
|
-
const values = parseValues(transformStr);
|
|
267
|
-
const transform = [];
|
|
268
|
-
values.forEach(item => {
|
|
269
|
-
const match = item.match(/([/\w]+)\((.+)\)/);
|
|
270
|
-
if (match && match.length >= 3) {
|
|
271
|
-
let key = match[1];
|
|
272
|
-
const val = match[2];
|
|
273
|
-
switch (key) {
|
|
274
|
-
case 'translateX':
|
|
275
|
-
case 'translateY':
|
|
276
|
-
case 'scaleX':
|
|
277
|
-
case 'scaleY':
|
|
278
|
-
case 'rotateX':
|
|
279
|
-
case 'rotateY':
|
|
280
|
-
case 'rotateZ':
|
|
281
|
-
case 'rotate':
|
|
282
|
-
case 'skewX':
|
|
283
|
-
case 'skewY':
|
|
284
|
-
case 'perspective':
|
|
285
|
-
// rotate 处理成 rotateZ
|
|
286
|
-
key = key === 'rotate' ? 'rotateZ' : key;
|
|
287
|
-
// 单个值处理
|
|
288
|
-
transform.push({ [key]: global.__formatValue(val) });
|
|
289
|
-
break;
|
|
290
|
-
case 'matrix':
|
|
291
|
-
transform.push({ [key]: parseValues(val, ',').map(val => +val) });
|
|
292
|
-
break;
|
|
293
|
-
case 'translate':
|
|
294
|
-
case 'scale':
|
|
295
|
-
case 'skew':
|
|
296
|
-
case 'translate3d': // x y 支持 z不支持
|
|
297
|
-
case 'scale3d': // x y 支持 z不支持
|
|
298
|
-
{
|
|
299
|
-
// 2 个以上的值处理
|
|
300
|
-
key = key.replace('3d', '');
|
|
301
|
-
const vals = parseValues(val, ',').splice(0, 3);
|
|
302
|
-
// scale(.5) === scaleX(.5) scaleY(.5)
|
|
303
|
-
if (vals.length === 1 && key === 'scale') {
|
|
304
|
-
vals.push(vals[0]);
|
|
305
|
-
}
|
|
306
|
-
const xyz = ['X', 'Y', 'Z'];
|
|
307
|
-
transform.push(...vals.map((v, index) => {
|
|
308
|
-
return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) };
|
|
309
|
-
}));
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
229
|
+
stringifyProps.forEach((prop) => {
|
|
230
|
+
if (isNumber(styleObj[prop])) {
|
|
231
|
+
styleObj[prop] = '' + styleObj[prop];
|
|
313
232
|
}
|
|
314
233
|
});
|
|
315
|
-
return transform;
|
|
316
|
-
}
|
|
317
|
-
// format style transform
|
|
318
|
-
function transformTransform(style) {
|
|
319
|
-
if (!style.transform || Array.isArray(style.transform))
|
|
320
|
-
return;
|
|
321
|
-
style.transform = parseTransform(style.transform);
|
|
322
|
-
}
|
|
323
|
-
function transformBoxShadow(styleObj) {
|
|
324
|
-
if (!styleObj.boxShadow)
|
|
325
|
-
return;
|
|
326
|
-
styleObj.boxShadow = parseValues(styleObj.boxShadow).reduce((res, i, idx) => {
|
|
327
|
-
return `${res}${idx === 0 ? '' : ' '}${global.__formatValue(i)}`;
|
|
328
|
-
}, '');
|
|
329
234
|
}
|
|
330
235
|
export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
331
236
|
const varStyle = {};
|
|
332
237
|
const unoVarStyle = {};
|
|
333
238
|
const normalStyle = {};
|
|
239
|
+
const normalStyleRef = useRef({});
|
|
240
|
+
const normalStyleChangedRef = useRef(false);
|
|
334
241
|
let hasVarDec = false;
|
|
335
242
|
let hasVarUse = false;
|
|
336
|
-
let hasSelfPercent = false;
|
|
337
243
|
const varKeyPaths = [];
|
|
338
244
|
const unoVarKeyPaths = [];
|
|
339
|
-
const percentKeyPaths = [];
|
|
340
|
-
const calcKeyPaths = [];
|
|
341
|
-
const envKeyPaths = [];
|
|
342
245
|
const [width, setWidth] = useState(0);
|
|
343
246
|
const [height, setHeight] = useState(0);
|
|
344
247
|
const navigation = useNavigation();
|
|
345
|
-
function varVisitor({
|
|
248
|
+
function varVisitor({ key, value, keyPath }) {
|
|
346
249
|
if (keyPath.length === 1) {
|
|
347
250
|
if (unoVarDecRegExp.test(key)) {
|
|
348
251
|
unoVarStyle[key] = value;
|
|
@@ -366,33 +269,6 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
366
269
|
hasVarUse = true;
|
|
367
270
|
varKeyPaths.push(keyPath.slice());
|
|
368
271
|
}
|
|
369
|
-
else {
|
|
370
|
-
visitOther({ target, key, value, keyPath });
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function envVisitor({ value, keyPath }) {
|
|
375
|
-
if (envUseRegExp.test(value)) {
|
|
376
|
-
envKeyPaths.push(keyPath.slice());
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
function calcVisitor({ value, keyPath }) {
|
|
380
|
-
if (calcUseRegExp.test(value)) {
|
|
381
|
-
calcKeyPaths.push(keyPath.slice());
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
function percentVisitor({ key, value, keyPath }) {
|
|
385
|
-
if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
386
|
-
hasSelfPercent = true;
|
|
387
|
-
percentKeyPaths.push(keyPath.slice());
|
|
388
|
-
}
|
|
389
|
-
else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
390
|
-
percentKeyPaths.push(keyPath.slice());
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function visitOther({ target, key, value, keyPath }) {
|
|
394
|
-
if (filterRegExp.test(value)) {
|
|
395
|
-
[envVisitor, percentVisitor, calcVisitor].forEach(visitor => visitor({ target, key, value, keyPath }));
|
|
396
272
|
}
|
|
397
273
|
}
|
|
398
274
|
// traverse var & generate normalStyle
|
|
@@ -413,61 +289,96 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
413
289
|
if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
|
|
414
290
|
varContextRef.current = newVarContext;
|
|
415
291
|
}
|
|
416
|
-
transformVar(normalStyle, varKeyPaths, varContextRef.current
|
|
292
|
+
transformVar(normalStyle, varKeyPaths, varContextRef.current);
|
|
417
293
|
}
|
|
418
294
|
// apply unocss var
|
|
419
295
|
if (unoVarKeyPaths.length) {
|
|
420
|
-
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle
|
|
296
|
+
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle);
|
|
421
297
|
}
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
transformCalc(normalStyle, calcKeyPaths, (value, key) => {
|
|
439
|
-
if (PERCENT_REGEX.test(value)) {
|
|
440
|
-
const resolved = resolvePercent(value, key, percentConfig);
|
|
441
|
-
return typeof resolved === 'number' ? resolved : 0;
|
|
298
|
+
const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current);
|
|
299
|
+
if (diff) {
|
|
300
|
+
normalStyleRef.current = clone;
|
|
301
|
+
normalStyleChangedRef.current = !normalStyleChangedRef.current;
|
|
302
|
+
}
|
|
303
|
+
const memoResult = useMemo(() => {
|
|
304
|
+
let hasSelfPercent = false;
|
|
305
|
+
let hasPositionFixed = false;
|
|
306
|
+
const percentKeyPaths = [];
|
|
307
|
+
const calcKeyPaths = [];
|
|
308
|
+
const envKeyPaths = [];
|
|
309
|
+
// transform can be memoized
|
|
310
|
+
function envVisitor({ value, keyPath }) {
|
|
311
|
+
if (envUseRegExp.test(value)) {
|
|
312
|
+
envKeyPaths.push(keyPath.slice());
|
|
313
|
+
}
|
|
442
314
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return formatted;
|
|
315
|
+
function calcVisitor({ value, keyPath }) {
|
|
316
|
+
if (calcUseRegExp.test(value)) {
|
|
317
|
+
calcKeyPaths.push(keyPath.slice());
|
|
447
318
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
319
|
+
}
|
|
320
|
+
function percentVisitor({ key, value, keyPath }) {
|
|
321
|
+
if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
322
|
+
hasSelfPercent = true;
|
|
323
|
+
percentKeyPaths.push(keyPath.slice());
|
|
324
|
+
}
|
|
325
|
+
else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
326
|
+
percentKeyPaths.push(keyPath.slice());
|
|
451
327
|
}
|
|
452
328
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
329
|
+
function transformPosition(styleObj) {
|
|
330
|
+
if (styleObj.position === 'fixed') {
|
|
331
|
+
hasPositionFixed = true;
|
|
332
|
+
styleObj.position = 'absolute';
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// traverse env & calc & percent
|
|
336
|
+
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
|
|
337
|
+
const percentConfig = {
|
|
338
|
+
width,
|
|
339
|
+
height,
|
|
340
|
+
fontSize: normalStyle.fontSize,
|
|
341
|
+
parentWidth,
|
|
342
|
+
parentHeight,
|
|
343
|
+
parentFontSize
|
|
344
|
+
};
|
|
345
|
+
// apply env
|
|
346
|
+
transformEnv(normalStyle, envKeyPaths, navigation);
|
|
347
|
+
// apply percent
|
|
348
|
+
transformPercent(normalStyle, percentKeyPaths, percentConfig);
|
|
349
|
+
// apply calc
|
|
350
|
+
transformCalc(normalStyle, calcKeyPaths, (value, key) => {
|
|
351
|
+
if (PERCENT_REGEX.test(value)) {
|
|
352
|
+
const resolved = resolvePercent(value, key, percentConfig);
|
|
353
|
+
return typeof resolved === 'number' ? resolved : 0;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
const formatted = global.__formatValue(value);
|
|
357
|
+
if (typeof formatted === 'number') {
|
|
358
|
+
return formatted;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
warn('calc() only support number, px, rpx, % temporarily.');
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
// apply position
|
|
367
|
+
transformPosition(normalStyle);
|
|
368
|
+
// transform number enum stringify
|
|
369
|
+
transformStringify(normalStyle);
|
|
370
|
+
return {
|
|
371
|
+
normalStyle,
|
|
372
|
+
hasSelfPercent,
|
|
373
|
+
hasPositionFixed
|
|
374
|
+
};
|
|
375
|
+
}, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize]);
|
|
376
|
+
return extendObject({
|
|
463
377
|
hasVarDec,
|
|
464
378
|
varContextRef,
|
|
465
379
|
setWidth,
|
|
466
|
-
setHeight
|
|
467
|
-
|
|
468
|
-
hasSelfPercent,
|
|
469
|
-
hasPositionFixed: positionMeta.hasPositionFixed
|
|
470
|
-
};
|
|
380
|
+
setHeight
|
|
381
|
+
}, memoResult);
|
|
471
382
|
}
|
|
472
383
|
export function traverseStyle(styleObj, visitors) {
|
|
473
384
|
const keyPath = [];
|
|
@@ -476,7 +387,12 @@ export function traverseStyle(styleObj, visitors) {
|
|
|
476
387
|
target.forEach((value, index) => {
|
|
477
388
|
const key = String(index);
|
|
478
389
|
keyPath.push(key);
|
|
479
|
-
visitors.forEach(visitor => visitor({
|
|
390
|
+
visitors.forEach(visitor => visitor({
|
|
391
|
+
target,
|
|
392
|
+
key,
|
|
393
|
+
value,
|
|
394
|
+
keyPath
|
|
395
|
+
}));
|
|
480
396
|
traverse(value);
|
|
481
397
|
keyPath.pop();
|
|
482
398
|
});
|
|
@@ -534,8 +450,19 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
534
450
|
}
|
|
535
451
|
if (enableOffset) {
|
|
536
452
|
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
537
|
-
const {
|
|
538
|
-
layoutRef.current = {
|
|
453
|
+
const { y: navigationY = 0 } = navigation?.layout || {};
|
|
454
|
+
layoutRef.current = {
|
|
455
|
+
x,
|
|
456
|
+
y: y - navigationY,
|
|
457
|
+
width,
|
|
458
|
+
height,
|
|
459
|
+
offsetLeft,
|
|
460
|
+
offsetTop: offsetTop - navigationY,
|
|
461
|
+
_x: x,
|
|
462
|
+
_y: y,
|
|
463
|
+
_offsetLeft: offsetLeft,
|
|
464
|
+
_offsetTop: offsetTop
|
|
465
|
+
};
|
|
539
466
|
});
|
|
540
467
|
}
|
|
541
468
|
onLayout && onLayout(e);
|
|
@@ -611,7 +538,7 @@ export function getCurrentPage(pageId) {
|
|
|
611
538
|
}
|
|
612
539
|
export function renderImage(imageProps, enableFastImage = false) {
|
|
613
540
|
const Component = enableFastImage ? FastImage : Image;
|
|
614
|
-
return
|
|
541
|
+
return <Component {...imageProps}/>;
|
|
615
542
|
}
|
|
616
543
|
export function pickStyle(styleObj = {}, pickedKeys, callback) {
|
|
617
544
|
return pickedKeys.reduce((acc, key) => {
|
|
@@ -662,11 +589,13 @@ export function useHover({ enableHover, hoverStartTime, hoverStayTime, disabled
|
|
|
662
589
|
const gesture = useMemo(() => {
|
|
663
590
|
return Gesture.Pan()
|
|
664
591
|
.onTouchesDown(() => {
|
|
665
|
-
|
|
592
|
+
'worklet';
|
|
593
|
+
runOnJS(setStartTimer)();
|
|
666
594
|
})
|
|
667
595
|
.onTouchesUp(() => {
|
|
668
|
-
|
|
669
|
-
|
|
596
|
+
'worklet';
|
|
597
|
+
runOnJS(setStayTimer)();
|
|
598
|
+
});
|
|
670
599
|
}, []);
|
|
671
600
|
if (gestureRef) {
|
|
672
601
|
gesture.simultaneousWithExternalGesture(gestureRef);
|
|
@@ -676,17 +605,3 @@ export function useHover({ enableHover, hoverStartTime, hoverStayTime, disabled
|
|
|
676
605
|
gesture
|
|
677
606
|
};
|
|
678
607
|
}
|
|
679
|
-
export function useRunOnJSCallback(callbackMapRef) {
|
|
680
|
-
const invokeCallback = useCallback((key, ...args) => {
|
|
681
|
-
const callback = callbackMapRef.current[key];
|
|
682
|
-
// eslint-disable-next-line node/no-callback-literal
|
|
683
|
-
if (isFunction(callback))
|
|
684
|
-
return callback(...args);
|
|
685
|
-
}, []);
|
|
686
|
-
useEffect(() => {
|
|
687
|
-
return () => {
|
|
688
|
-
callbackMapRef.current = {};
|
|
689
|
-
};
|
|
690
|
-
}, []);
|
|
691
|
-
return invokeCallback;
|
|
692
|
-
}
|
package/package.json
CHANGED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useRef, createElement } from 'react';
|
|
2
|
-
import { View, Image, StyleSheet, Text, TouchableOpacity } from 'react-native';
|
|
3
|
-
import FastImage from '@d11/react-native-fast-image';
|
|
4
|
-
const asyncChunkMap = new Map();
|
|
5
|
-
const styles = StyleSheet.create({
|
|
6
|
-
container: {
|
|
7
|
-
flex: 1,
|
|
8
|
-
padding: 20,
|
|
9
|
-
backgroundColor: '#fff'
|
|
10
|
-
},
|
|
11
|
-
loadingImage: {
|
|
12
|
-
width: 100,
|
|
13
|
-
height: 100,
|
|
14
|
-
marginTop: 220,
|
|
15
|
-
alignSelf: 'center'
|
|
16
|
-
},
|
|
17
|
-
buttonText: {
|
|
18
|
-
color: '#fff',
|
|
19
|
-
fontSize: 16,
|
|
20
|
-
fontWeight: '500',
|
|
21
|
-
textAlign: 'center'
|
|
22
|
-
},
|
|
23
|
-
errorImage: {
|
|
24
|
-
marginTop: 80,
|
|
25
|
-
width: 220,
|
|
26
|
-
aspectRatio: 1,
|
|
27
|
-
alignSelf: 'center'
|
|
28
|
-
},
|
|
29
|
-
errorText: {
|
|
30
|
-
fontSize: 16,
|
|
31
|
-
textAlign: 'center',
|
|
32
|
-
color: '#333',
|
|
33
|
-
marginBottom: 20
|
|
34
|
-
},
|
|
35
|
-
retryButton: {
|
|
36
|
-
position: 'absolute',
|
|
37
|
-
bottom: 54,
|
|
38
|
-
left: 20,
|
|
39
|
-
right: 20,
|
|
40
|
-
backgroundColor: '#fff',
|
|
41
|
-
paddingVertical: 15,
|
|
42
|
-
borderRadius: 30,
|
|
43
|
-
marginTop: 40,
|
|
44
|
-
borderWidth: 1,
|
|
45
|
-
borderColor: '#FF5F00'
|
|
46
|
-
},
|
|
47
|
-
retryButtonText: {
|
|
48
|
-
color: '#FF5F00',
|
|
49
|
-
fontSize: 16,
|
|
50
|
-
fontWeight: '500',
|
|
51
|
-
textAlign: 'center'
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
const DefaultFallback = ({ onReload }) => {
|
|
55
|
-
return (<View style={styles.container}>
|
|
56
|
-
<Image source={{
|
|
57
|
-
uri: 'https://dpubstatic.udache.com/static/dpubimg/Vak5mZvezPpKV5ZJI6P9b_drn-fallbak.png'
|
|
58
|
-
}} style={styles.errorImage} resizeMode="contain"/>
|
|
59
|
-
<Text style={styles.errorText}>网络出了点问题,请查看网络环境</Text>
|
|
60
|
-
<TouchableOpacity style={styles.retryButton} onPress={onReload} activeOpacity={0.7}>
|
|
61
|
-
<Text style={styles.retryButtonText}>点击重试</Text>
|
|
62
|
-
</TouchableOpacity>
|
|
63
|
-
</View>);
|
|
64
|
-
};
|
|
65
|
-
const DefaultLoading = () => {
|
|
66
|
-
return (<View style={styles.container}>
|
|
67
|
-
<FastImage style={styles.loadingImage} source={{
|
|
68
|
-
uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif'
|
|
69
|
-
}} resizeMode={FastImage.resizeMode.contain}></FastImage>
|
|
70
|
-
</View>);
|
|
71
|
-
};
|
|
72
|
-
const AsyncSuspense = ({ type, chunkName, moduleId, innerProps, getLoading, getFallback, getChildren }) => {
|
|
73
|
-
const [status, setStatus] = useState('pending');
|
|
74
|
-
const chunkLoaded = asyncChunkMap.has(moduleId);
|
|
75
|
-
const loadChunkPromise = useRef(null);
|
|
76
|
-
const reloadPage = useCallback(() => {
|
|
77
|
-
setStatus('pending');
|
|
78
|
-
}, []);
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
let cancelled = false;
|
|
81
|
-
if (!chunkLoaded && status === 'pending') {
|
|
82
|
-
if (loadChunkPromise.current) {
|
|
83
|
-
loadChunkPromise
|
|
84
|
-
.current.then((res) => {
|
|
85
|
-
if (cancelled)
|
|
86
|
-
return;
|
|
87
|
-
asyncChunkMap.set(moduleId, res);
|
|
88
|
-
setStatus('loaded');
|
|
89
|
-
})
|
|
90
|
-
.catch((e) => {
|
|
91
|
-
if (cancelled)
|
|
92
|
-
return;
|
|
93
|
-
if (type === 'component') {
|
|
94
|
-
global.__mpxAppCbs.lazyLoad.forEach((cb) => {
|
|
95
|
-
// eslint-disable-next-line node/no-callback-literal
|
|
96
|
-
cb({
|
|
97
|
-
type: 'subpackage',
|
|
98
|
-
subpackage: [chunkName],
|
|
99
|
-
errMsg: `loadSubpackage: ${e.type}`
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.onLazyLoadPageError === 'function') {
|
|
104
|
-
mpxGlobal.__mpx.config.rnConfig.onLazyLoadPageError({
|
|
105
|
-
subpackage: chunkName,
|
|
106
|
-
errType: e.type
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
loadChunkPromise.current = null;
|
|
110
|
-
setStatus('error');
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return () => {
|
|
115
|
-
cancelled = true;
|
|
116
|
-
};
|
|
117
|
-
}, [status]);
|
|
118
|
-
if (chunkLoaded) {
|
|
119
|
-
const Comp = asyncChunkMap.get(moduleId);
|
|
120
|
-
return createElement(Comp, innerProps);
|
|
121
|
-
}
|
|
122
|
-
else if (status === 'error') {
|
|
123
|
-
if (type === 'page') {
|
|
124
|
-
const fallback = getFallback ? getFallback() : DefaultFallback;
|
|
125
|
-
return createElement(fallback, { onReload: reloadPage });
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return getFallback ? createElement(getFallback(), innerProps) : null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
if (!loadChunkPromise.current) {
|
|
133
|
-
loadChunkPromise.current = getChildren();
|
|
134
|
-
}
|
|
135
|
-
if (type === 'page') {
|
|
136
|
-
const loading = getLoading ? getLoading() : DefaultLoading;
|
|
137
|
-
return createElement(loading);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return getFallback ? createElement(getFallback(), innerProps) : null;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
AsyncSuspense.displayName = 'MpxAsyncSuspense';
|
|
145
|
-
export default AsyncSuspense;
|