@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.71

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 (126) hide show
  1. package/LICENSE +433 -0
  2. package/README.md +1 -1
  3. package/lib/config.js +0 -14
  4. package/lib/dependencies/ResolveDependency.js +0 -5
  5. package/lib/index.js +7 -38
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +0 -53
  8. package/lib/parser.js +1 -1
  9. package/lib/platform/json/wx/index.js +21 -8
  10. package/lib/platform/style/wx/index.js +51 -54
  11. package/lib/platform/template/wx/component-config/button.js +2 -14
  12. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  13. package/lib/platform/template/wx/component-config/image.js +0 -4
  14. package/lib/platform/template/wx/component-config/index.js +1 -1
  15. package/lib/platform/template/wx/component-config/input.js +0 -4
  16. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  17. package/lib/platform/template/wx/component-config/picker-view.js +1 -5
  18. package/lib/platform/template/wx/component-config/rich-text.js +6 -2
  19. package/lib/platform/template/wx/component-config/scroll-view.js +1 -5
  20. package/lib/platform/template/wx/component-config/switch.js +0 -4
  21. package/lib/platform/template/wx/component-config/text.js +0 -4
  22. package/lib/platform/template/wx/component-config/textarea.js +0 -5
  23. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  24. package/lib/platform/template/wx/component-config/view.js +0 -4
  25. package/lib/platform/template/wx/index.js +1 -131
  26. package/lib/resolve-loader.js +1 -4
  27. package/lib/runtime/components/react/context.ts +8 -0
  28. package/lib/runtime/components/react/dist/context.js +2 -0
  29. package/lib/runtime/components/react/dist/getInnerListeners.js +39 -37
  30. package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
  31. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  32. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
  33. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +93 -58
  34. package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +10 -14
  36. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +94 -81
  37. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +19 -16
  38. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
  39. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
  40. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
  41. package/lib/runtime/components/react/dist/mpx-swiper.jsx +435 -371
  42. package/lib/runtime/components/react/dist/mpx-view.jsx +18 -53
  43. package/lib/runtime/components/react/dist/pickerFaces.js +3 -8
  44. package/lib/runtime/components/react/dist/pickerVIewContext.js +5 -0
  45. package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerViewIndicator.jsx} +6 -6
  46. package/lib/runtime/components/react/dist/pickerViewMask.jsx +2 -2
  47. package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -10
  48. package/lib/runtime/components/react/dist/utils.jsx +162 -70
  49. package/lib/runtime/components/react/event.config.ts +25 -26
  50. package/lib/runtime/components/react/getInnerListeners.ts +236 -182
  51. package/lib/runtime/components/react/mpx-button.tsx +27 -69
  52. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  53. package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
  54. package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
  55. package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
  56. package/lib/runtime/components/react/mpx-form.tsx +15 -20
  57. package/lib/runtime/components/react/mpx-icon.tsx +2 -2
  58. package/lib/runtime/components/react/mpx-image.tsx +87 -47
  59. package/lib/runtime/components/react/mpx-input.tsx +24 -32
  60. package/lib/runtime/components/react/mpx-label.tsx +12 -14
  61. package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
  62. package/lib/runtime/components/react/mpx-movable-view.tsx +133 -92
  63. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  64. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
  65. package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
  66. package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
  67. package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
  68. package/lib/runtime/components/react/mpx-radio.tsx +19 -25
  69. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  70. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  71. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  72. package/lib/runtime/components/react/mpx-scroll-view.tsx +53 -43
  73. package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
  74. package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
  75. package/lib/runtime/components/react/mpx-switch.tsx +19 -15
  76. package/lib/runtime/components/react/mpx-text.tsx +8 -16
  77. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  78. package/lib/runtime/components/react/mpx-view.tsx +28 -77
  79. package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
  80. package/lib/runtime/components/react/pickerFaces.ts +10 -7
  81. package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
  82. package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
  83. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  84. package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
  85. package/lib/runtime/components/react/types/global.d.ts +12 -1
  86. package/lib/runtime/components/react/useAnimationHooks.ts +60 -15
  87. package/lib/runtime/components/react/utils.tsx +175 -71
  88. package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
  89. package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
  90. package/lib/runtime/components/web/mpx-web-view.vue +34 -20
  91. package/lib/runtime/optionProcessor.js +0 -22
  92. package/lib/style-compiler/index.js +1 -1
  93. package/lib/style-compiler/plugins/scope-id.js +30 -2
  94. package/lib/template-compiler/compiler.js +91 -39
  95. package/lib/utils/env.js +1 -6
  96. package/lib/utils/pre-process-json.js +9 -5
  97. package/lib/wxss/loader.js +15 -2
  98. package/package.json +4 -7
  99. package/lib/dependencies/AddEntryDependency.js +0 -24
  100. package/lib/runtime/components/react/dist/types/common.js +0 -1
  101. package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
  102. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
  103. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  104. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  105. package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
  106. package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
  107. package/lib/runtime/components/tenon/tenon-button.vue +0 -309
  108. package/lib/runtime/components/tenon/tenon-image.vue +0 -66
  109. package/lib/runtime/components/tenon/tenon-input.vue +0 -171
  110. package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
  111. package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
  112. package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
  113. package/lib/runtime/components/tenon/tenon-text.vue +0 -70
  114. package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
  115. package/lib/runtime/components/tenon/tenon-view.vue +0 -93
  116. package/lib/runtime/components/web/event.js +0 -105
  117. package/lib/runtime/optionProcessor.tenon.js +0 -84
  118. package/lib/style-compiler/plugins/hm.js +0 -20
  119. package/lib/tenon/index.js +0 -117
  120. package/lib/tenon/processJSON.js +0 -352
  121. package/lib/tenon/processScript.js +0 -203
  122. package/lib/tenon/processStyles.js +0 -21
  123. package/lib/tenon/processTemplate.js +0 -126
  124. package/lib/tenon/script-helper.js +0 -223
  125. package/lib/utils/get-relative-path.js +0 -25
  126. /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
@@ -1,10 +1,13 @@
1
1
  import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
2
2
  import { Image } from 'react-native';
3
- import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
4
- import { VarContext } from './context';
3
+ import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils';
4
+ import { VarContext, ScrollViewContext } from './context';
5
5
  import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
6
6
  import { initialWindowMetrics } from 'react-native-safe-area-context';
7
+ import { useNavigation } from '@react-navigation/native';
7
8
  import FastImage from '@d11/react-native-fast-image';
9
+ import { runOnJS } from 'react-native-reanimated';
10
+ import { Gesture } from 'react-native-gesture-handler';
8
11
  export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
9
12
  export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
10
13
  export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
@@ -15,8 +18,12 @@ export const DEFAULT_FONT_SIZE = 16;
15
18
  export const HIDDEN_STYLE = {
16
19
  opacity: 0
17
20
  };
18
- const varDecRegExp = /^--.*/;
21
+ export const isIOS = __mpx_mode__ === 'ios';
22
+ export const isAndroid = __mpx_mode__ === 'android';
23
+ const varDecRegExp = /^--/;
19
24
  const varUseRegExp = /var\(/;
25
+ const unoVarDecRegExp = /^--un-/;
26
+ const unoVarUseRegExp = /var\(--un-/;
20
27
  const calcUseRegExp = /calc\(/;
21
28
  const envUseRegExp = /env\(/;
22
29
  const safeAreaInsetMap = {
@@ -25,13 +32,12 @@ const safeAreaInsetMap = {
25
32
  'safe-area-inset-bottom': 'bottom',
26
33
  'safe-area-inset-left': 'left'
27
34
  };
28
- function getSafeAreaInset(name) {
29
- const navigation = getFocusedNavigation();
35
+ function getSafeAreaInset(name, navigation) {
30
36
  const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
31
37
  return insets[safeAreaInsetMap[name]];
32
38
  }
33
39
  export function omit(obj, fields) {
34
- const shallowCopy = Object.assign({}, obj);
40
+ const shallowCopy = extendObject({}, obj);
35
41
  for (let i = 0; i < fields.length; i += 1) {
36
42
  const key = fields[i];
37
43
  delete shallowCopy[key];
@@ -69,7 +75,7 @@ export const parseInlineStyle = (inlineStyle = '') => {
69
75
  if (rest.length || !v || !k)
70
76
  return styleObj;
71
77
  const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
72
- return Object.assign(styleObj, { [key]: global.__formatValue(v.trim()) });
78
+ return extendObject(styleObj, { [key]: global.__formatValue(v.trim()) });
73
79
  }, {});
74
80
  };
75
81
  export const parseUrl = (cssUrl = '') => {
@@ -192,7 +198,7 @@ function transformVar(styleObj, varKeyPaths, varContext) {
192
198
  });
193
199
  });
194
200
  }
195
- function transformEnv(styleObj, envKeyPaths) {
201
+ function transformEnv(styleObj, envKeyPaths, navigation) {
196
202
  envKeyPaths.forEach((envKeyPath) => {
197
203
  setStyle(styleObj, envKeyPath, ({ target, key, value }) => {
198
204
  const parsed = parseFunc(value, 'env');
@@ -200,7 +206,7 @@ function transformEnv(styleObj, envKeyPaths) {
200
206
  parsed.forEach(({ start, end, args }) => {
201
207
  const name = args[0];
202
208
  const fallback = args[1] || '';
203
- const value = '' + (getSafeAreaInset(name) ?? global.__formatValue(fallback));
209
+ const value = '' + (getSafeAreaInset(name, navigation) ?? global.__formatValue(fallback));
204
210
  replaced.replace(start, end - 1, value);
205
211
  });
206
212
  target[key] = global.__formatValue(replaced.source());
@@ -238,19 +244,27 @@ function transformStringify(styleObj) {
238
244
  }
239
245
  export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
240
246
  const varStyle = {};
247
+ const unoVarStyle = {};
241
248
  const normalStyle = {};
249
+ const normalStyleRef = useRef({});
250
+ const normalStyleChangedRef = useRef(false);
242
251
  let hasVarDec = false;
243
252
  let hasVarUse = false;
244
253
  let hasSelfPercent = false;
245
254
  const varKeyPaths = [];
255
+ const unoVarKeyPaths = [];
246
256
  const percentKeyPaths = [];
247
257
  const calcKeyPaths = [];
248
258
  const envKeyPaths = [];
249
259
  const [width, setWidth] = useState(0);
250
260
  const [height, setHeight] = useState(0);
261
+ const navigation = useNavigation();
251
262
  function varVisitor({ key, value, keyPath }) {
252
263
  if (keyPath.length === 1) {
253
- if (varDecRegExp.test(key)) {
264
+ if (unoVarDecRegExp.test(key)) {
265
+ unoVarStyle[key] = value;
266
+ }
267
+ else if (varDecRegExp.test(key)) {
254
268
  hasVarDec = true;
255
269
  varStyle[key] = value;
256
270
  }
@@ -260,12 +274,18 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
260
274
  }
261
275
  }
262
276
  // 对于var定义中使用的var无需替换值,可以通过resolveVar递归解析出值
263
- if (!varDecRegExp.test(key) && varUseRegExp.test(value)) {
264
- hasVarUse = true;
265
- varKeyPaths.push(keyPath.slice());
277
+ if (!varDecRegExp.test(key)) {
278
+ // 一般情况下一个样式属性中不会混用unocss var和普通css var,可分开进行互斥处理
279
+ if (unoVarUseRegExp.test(value)) {
280
+ unoVarKeyPaths.push(keyPath.slice());
281
+ }
282
+ else if (varUseRegExp.test(value)) {
283
+ hasVarUse = true;
284
+ varKeyPaths.push(keyPath.slice());
285
+ }
266
286
  }
267
287
  }
268
- // traverse var
288
+ // traverse var & generate normalStyle
269
289
  traverseStyle(styleObj, [varVisitor]);
270
290
  hasVarDec = hasVarDec || !!externalVarContext;
271
291
  enableVar = enableVar || hasVarDec || hasVarUse;
@@ -273,78 +293,92 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
273
293
  if (enableVarRef.current !== enableVar) {
274
294
  error('css variable use/declare should be stable in the component lifecycle, or you can set [enable-var] with true.');
275
295
  }
276
- // apply var
296
+ // apply css var
277
297
  const varContextRef = useRef({});
278
298
  if (enableVarRef.current) {
299
+ // eslint-disable-next-line react-hooks/rules-of-hooks
279
300
  const varContext = useContext(VarContext);
280
- const newVarContext = Object.assign({}, varContext, externalVarContext, varStyle);
301
+ const newVarContext = extendObject({}, varContext, externalVarContext, varStyle);
281
302
  // 缓存比较newVarContext是否发生变化
282
303
  if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
283
304
  varContextRef.current = newVarContext;
284
305
  }
285
306
  transformVar(normalStyle, varKeyPaths, varContextRef.current);
286
307
  }
287
- function envVisitor({ value, keyPath }) {
288
- if (envUseRegExp.test(value)) {
289
- envKeyPaths.push(keyPath.slice());
290
- }
308
+ // apply unocss var
309
+ if (unoVarKeyPaths.length) {
310
+ transformVar(normalStyle, unoVarKeyPaths, unoVarStyle);
291
311
  }
292
- function calcVisitor({ value, keyPath }) {
293
- if (calcUseRegExp.test(value)) {
294
- calcKeyPaths.push(keyPath.slice());
295
- }
312
+ const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current);
313
+ if (diff) {
314
+ normalStyleRef.current = clone;
315
+ normalStyleChangedRef.current = !normalStyleChangedRef.current;
296
316
  }
297
- function percentVisitor({ key, value, keyPath }) {
298
- if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
299
- hasSelfPercent = true;
300
- percentKeyPaths.push(keyPath.slice());
317
+ const memoResult = useMemo(() => {
318
+ // transform can be memoized
319
+ function envVisitor({ value, keyPath }) {
320
+ if (envUseRegExp.test(value)) {
321
+ envKeyPaths.push(keyPath.slice());
322
+ }
301
323
  }
302
- else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
303
- percentKeyPaths.push(keyPath.slice());
324
+ function calcVisitor({ value, keyPath }) {
325
+ if (calcUseRegExp.test(value)) {
326
+ calcKeyPaths.push(keyPath.slice());
327
+ }
304
328
  }
305
- }
306
- // traverse env & calc & percent
307
- traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
308
- const percentConfig = {
309
- width,
310
- height,
311
- fontSize: normalStyle.fontSize,
312
- parentWidth,
313
- parentHeight,
314
- parentFontSize
315
- };
316
- // apply env
317
- transformEnv(normalStyle, envKeyPaths);
318
- // apply percent
319
- transformPercent(normalStyle, percentKeyPaths, percentConfig);
320
- // apply calc
321
- transformCalc(normalStyle, calcKeyPaths, (value, key) => {
322
- if (PERCENT_REGEX.test(value)) {
323
- const resolved = resolvePercent(value, key, percentConfig);
324
- return typeof resolved === 'number' ? resolved : 0;
329
+ function percentVisitor({ key, value, keyPath }) {
330
+ if (hasOwn(selfPercentRule, key) && PERCENT_REGEX.test(value)) {
331
+ hasSelfPercent = true;
332
+ percentKeyPaths.push(keyPath.slice());
333
+ }
334
+ else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
335
+ percentKeyPaths.push(keyPath.slice());
336
+ }
325
337
  }
326
- else {
327
- const formatted = global.__formatValue(value);
328
- if (typeof formatted === 'number') {
329
- return formatted;
338
+ // traverse env & calc & percent
339
+ traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
340
+ const percentConfig = {
341
+ width,
342
+ height,
343
+ fontSize: normalStyle.fontSize,
344
+ parentWidth,
345
+ parentHeight,
346
+ parentFontSize
347
+ };
348
+ // apply env
349
+ transformEnv(normalStyle, envKeyPaths, navigation);
350
+ // apply percent
351
+ transformPercent(normalStyle, percentKeyPaths, percentConfig);
352
+ // apply calc
353
+ transformCalc(normalStyle, calcKeyPaths, (value, key) => {
354
+ if (PERCENT_REGEX.test(value)) {
355
+ const resolved = resolvePercent(value, key, percentConfig);
356
+ return typeof resolved === 'number' ? resolved : 0;
330
357
  }
331
358
  else {
332
- warn('calc() only support number, px, rpx, % temporarily.');
333
- return 0;
359
+ const formatted = global.__formatValue(value);
360
+ if (typeof formatted === 'number') {
361
+ return formatted;
362
+ }
363
+ else {
364
+ warn('calc() only support number, px, rpx, % temporarily.');
365
+ return 0;
366
+ }
334
367
  }
335
- }
336
- });
337
- // transform number enum stringify
338
- transformStringify(normalStyle);
339
- return {
340
- normalStyle,
341
- hasSelfPercent,
368
+ });
369
+ // transform number enum stringify
370
+ transformStringify(normalStyle);
371
+ return {
372
+ normalStyle,
373
+ hasSelfPercent
374
+ };
375
+ }, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize]);
376
+ return extendObject({
342
377
  hasVarDec,
343
- enableVarRef,
344
378
  varContextRef,
345
379
  setWidth,
346
380
  setHeight
347
- };
381
+ }, memoResult);
348
382
  }
349
383
  export function traverseStyle(styleObj, visitors) {
350
384
  const keyPath = [];
@@ -447,13 +481,14 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
447
481
  export const debounce = (func, delay) => {
448
482
  let timer;
449
483
  const wrapper = (...args) => {
450
- clearTimeout(timer);
484
+ timer && clearTimeout(timer);
451
485
  timer = setTimeout(() => {
452
486
  func(...args);
453
487
  }, delay);
454
488
  };
455
489
  wrapper.clear = () => {
456
- clearTimeout(timer);
490
+ timer && clearTimeout(timer);
491
+ timer = null;
457
492
  };
458
493
  return wrapper;
459
494
  };
@@ -466,12 +501,12 @@ export const useStableCallback = (callback) => {
466
501
  ref.current = callback;
467
502
  return useCallback((...args) => ref.current?.(...args), []);
468
503
  };
469
- export const usePrevious = (value) => {
470
- const ref = useRef(undefined);
504
+ export function usePrevious(value) {
505
+ const ref = useRef();
471
506
  const prev = ref.current;
472
507
  ref.current = value;
473
508
  return prev;
474
- };
509
+ }
475
510
  export function flatGesture(gestures = []) {
476
511
  return (gestures && gestures.flatMap((gesture) => {
477
512
  if (gesture && gesture.nodeRefs) {
@@ -500,3 +535,60 @@ export function pickStyle(styleObj = {}, pickedKeys, callback) {
500
535
  return acc;
501
536
  }, {});
502
537
  }
538
+ export function useHover({ enableHover, hoverStartTime, hoverStayTime, disabled }) {
539
+ const enableHoverRef = useRef(enableHover);
540
+ if (enableHoverRef.current !== enableHover) {
541
+ error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.');
542
+ }
543
+ if (!enableHoverRef.current)
544
+ return { isHover: false };
545
+ // eslint-disable-next-line react-hooks/rules-of-hooks
546
+ const gestureRef = useContext(ScrollViewContext).gestureRef;
547
+ // eslint-disable-next-line react-hooks/rules-of-hooks
548
+ const [isHover, setIsHover] = useState(false);
549
+ // eslint-disable-next-line react-hooks/rules-of-hooks
550
+ const dataRef = useRef({});
551
+ // eslint-disable-next-line react-hooks/rules-of-hooks
552
+ useEffect(() => {
553
+ return () => {
554
+ dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
555
+ dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
556
+ };
557
+ }, []);
558
+ const setStartTimer = () => {
559
+ if (disabled)
560
+ return;
561
+ dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
562
+ dataRef.current.startTimer = setTimeout(() => {
563
+ setIsHover(true);
564
+ }, +hoverStartTime);
565
+ };
566
+ const setStayTimer = () => {
567
+ if (disabled)
568
+ return;
569
+ dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
570
+ dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
571
+ dataRef.current.stayTimer = setTimeout(() => {
572
+ setIsHover(false);
573
+ }, +hoverStayTime);
574
+ };
575
+ // eslint-disable-next-line react-hooks/rules-of-hooks
576
+ const gesture = useMemo(() => {
577
+ return Gesture.Pan()
578
+ .onTouchesDown(() => {
579
+ 'worklet';
580
+ runOnJS(setStartTimer)();
581
+ })
582
+ .onTouchesUp(() => {
583
+ 'worklet';
584
+ runOnJS(setStayTimer)();
585
+ });
586
+ }, []);
587
+ if (gestureRef) {
588
+ gesture.simultaneousWithExternalGesture(gestureRef);
589
+ }
590
+ return {
591
+ isHover,
592
+ gesture
593
+ };
594
+ }
@@ -2,31 +2,30 @@ interface EventConfig {
2
2
  [key: string]: string[];
3
3
  }
4
4
 
5
- const eventConfigMap: EventConfig = {
6
- bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
7
- bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
8
- bindtouchstart: ['onTouchStart'],
9
- bindtouchmove: ['onTouchMove'],
10
- bindtouchend: ['onTouchEnd'],
11
- bindtouchcancel: ['onTouchCancel'],
12
- catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
13
- catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
14
- catchtouchstart: ['onTouchStart'],
15
- catchtouchmove: ['onTouchMove'],
16
- catchtouchend: ['onTouchEnd'],
17
- catchtouchcancel: ['onTouchCancel'],
18
- 'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
19
- 'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
20
- 'capture-bindtouchstart': ['onTouchStartCapture'],
21
- 'capture-bindtouchmove': ['onTouchMoveCapture'],
22
- 'capture-bindtouchend': ['onTouchEndCapture'],
23
- 'capture-bindtouchcancel': ['onTouchCancelCapture'],
24
- 'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
25
- 'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
26
- 'capture-catchtouchstart': ['onTouchStartCapture'],
27
- 'capture-catchtouchmove': ['onTouchMoveCapture'],
28
- 'capture-catchtouchend': ['onTouchEndCapture'],
29
- 'capture-catchtouchcancel': ['onTouchCancelCapture']
5
+ const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } = {
6
+ bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
7
+ bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
8
+ bindtouchstart: { bitFlag: '2', events: ['onTouchStart'] },
9
+ bindtouchmove: { bitFlag: '3', events: ['onTouchMove'] },
10
+ bindtouchend: { bitFlag: '4', events: ['onTouchEnd'] },
11
+ bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'] },
12
+ catchtap: { bitFlag: '6', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
13
+ catchlongpress: { bitFlag: '7', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
14
+ catchtouchstart: { bitFlag: '8', events: ['onTouchStart'] },
15
+ catchtouchmove: { bitFlag: '9', events: ['onTouchMove'] },
16
+ catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'] },
17
+ catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'] },
18
+ 'capture-bindtap': { bitFlag: 'c', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
19
+ 'capture-bindlongpress': { bitFlag: 'd', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
20
+ 'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'] },
21
+ 'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'] },
22
+ 'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'] },
23
+ 'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'] },
24
+ 'capture-catchtap': { bitFlag: 'i', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
25
+ 'capture-catchlongpress': { bitFlag: 'j', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
26
+ 'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'] },
27
+ 'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'] },
28
+ 'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
29
+ 'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
30
30
  }
31
-
32
31
  export default eventConfigMap