@mpxjs/webpack-plugin 2.9.70-alpha.1 → 2.9.70-alpha.2
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/config.js +3 -1
- package/lib/file-loader.js +5 -0
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/picker-view.js +1 -5
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/platform/template/wx/index.js +3 -5
- package/lib/react/processScript.js +6 -3
- package/lib/react/script-helper.js +5 -1
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +0 -2
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -31
- package/lib/runtime/components/react/dist/mpx-button.jsx +11 -11
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-icon/icons/cancel.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/clear.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/download.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/info.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/search.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/success.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/success_no_circle.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/waiting.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/warn.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +50 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +12 -15
- package/lib/runtime/components/react/dist/mpx-input.jsx +10 -8
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +92 -57
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +1 -2
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +10 -14
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +79 -67
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +19 -16
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +2 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +13 -7
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +382 -325
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -13
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +22 -118
- package/lib/runtime/components/react/dist/pickerFaces.js +1 -6
- package/lib/runtime/components/react/dist/pickerVIewContext.js +5 -0
- package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerViewIndicator.jsx} +6 -6
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +2 -2
- package/lib/runtime/components/react/dist/useAnimationHooks.js +15 -10
- package/lib/runtime/components/react/dist/utils.jsx +117 -84
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +236 -182
- package/lib/runtime/components/react/mpx-button.tsx +27 -69
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
- package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
- package/lib/runtime/components/react/mpx-form.tsx +15 -20
- package/lib/runtime/components/react/mpx-icon/icons/cancel.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/clear.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/download.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/info.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/search.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/success.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/success_no_circle.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/waiting.png +0 -0
- package/lib/runtime/components/react/mpx-icon/icons/warn.png +0 -0
- package/lib/runtime/components/react/mpx-icon/index.tsx +111 -0
- package/lib/runtime/components/react/mpx-image.tsx +99 -47
- package/lib/runtime/components/react/mpx-input.tsx +33 -39
- package/lib/runtime/components/react/mpx-label.tsx +12 -14
- package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
- package/lib/runtime/components/react/mpx-movable-view.tsx +133 -92
- package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
- package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
- package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
- package/lib/runtime/components/react/mpx-radio.tsx +19 -25
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +62 -49
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
- package/lib/runtime/components/react/mpx-switch.tsx +19 -15
- package/lib/runtime/components/react/mpx-text.tsx +8 -16
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +28 -77
- package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
- package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
- package/lib/runtime/components/react/types/global.d.ts +14 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +60 -15
- package/lib/runtime/components/react/utils.tsx +175 -71
- package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
- package/lib/runtime/components/web/mpx-web-view.vue +34 -20
- package/lib/runtime/optionProcessor.js +0 -22
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/compiler.js +96 -29
- package/lib/utils/pre-process-json.js +9 -5
- package/lib/wxss/loader.js +15 -2
- package/package.json +4 -3
- package/lib/runtime/components/react/dist/locale-provider.jsx +0 -15
- package/lib/runtime/components/react/dist/mpx-icon.jsx +0 -41
- package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +0 -23
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +0 -124
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +0 -40
- package/lib/runtime/components/react/dist/mpx-portal.jsx +0 -12
- package/lib/runtime/components/react/dist/mpx-provider.jsx +0 -31
- package/lib/runtime/components/react/dist/types/common.js +0 -1
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
- package/lib/runtime/components/react/mpx-icon.tsx +0 -102
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
- package/lib/runtime/components/web/event.js +0 -105
- /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
|
|
2
|
-
import { Image
|
|
3
|
-
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn
|
|
2
|
+
import { Image } from 'react-native';
|
|
3
|
+
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils';
|
|
4
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';
|
|
8
9
|
import { runOnJS } from 'react-native-reanimated';
|
|
9
10
|
import { Gesture } from 'react-native-gesture-handler';
|
|
@@ -17,10 +18,12 @@ export const DEFAULT_FONT_SIZE = 16;
|
|
|
17
18
|
export const HIDDEN_STYLE = {
|
|
18
19
|
opacity: 0
|
|
19
20
|
};
|
|
20
|
-
export const isIOS =
|
|
21
|
-
export const isAndroid =
|
|
22
|
-
const varDecRegExp =
|
|
21
|
+
export const isIOS = __mpx_mode__ === 'ios';
|
|
22
|
+
export const isAndroid = __mpx_mode__ === 'android';
|
|
23
|
+
const varDecRegExp = /^--/;
|
|
23
24
|
const varUseRegExp = /var\(/;
|
|
25
|
+
const unoVarDecRegExp = /^--un-/;
|
|
26
|
+
const unoVarUseRegExp = /var\(--un-/;
|
|
24
27
|
const calcUseRegExp = /calc\(/;
|
|
25
28
|
const envUseRegExp = /env\(/;
|
|
26
29
|
const safeAreaInsetMap = {
|
|
@@ -29,13 +32,12 @@ const safeAreaInsetMap = {
|
|
|
29
32
|
'safe-area-inset-bottom': 'bottom',
|
|
30
33
|
'safe-area-inset-left': 'left'
|
|
31
34
|
};
|
|
32
|
-
function getSafeAreaInset(name) {
|
|
33
|
-
const navigation = getFocusedNavigation();
|
|
35
|
+
function getSafeAreaInset(name, navigation) {
|
|
34
36
|
const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
|
|
35
37
|
return insets[safeAreaInsetMap[name]];
|
|
36
38
|
}
|
|
37
39
|
export function omit(obj, fields) {
|
|
38
|
-
const shallowCopy =
|
|
40
|
+
const shallowCopy = extendObject({}, obj);
|
|
39
41
|
for (let i = 0; i < fields.length; i += 1) {
|
|
40
42
|
const key = fields[i];
|
|
41
43
|
delete shallowCopy[key];
|
|
@@ -73,7 +75,7 @@ export const parseInlineStyle = (inlineStyle = '') => {
|
|
|
73
75
|
if (rest.length || !v || !k)
|
|
74
76
|
return styleObj;
|
|
75
77
|
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
|
|
76
|
-
return
|
|
78
|
+
return extendObject(styleObj, { [key]: global.__formatValue(v.trim()) });
|
|
77
79
|
}, {});
|
|
78
80
|
};
|
|
79
81
|
export const parseUrl = (cssUrl = '') => {
|
|
@@ -196,7 +198,7 @@ function transformVar(styleObj, varKeyPaths, varContext) {
|
|
|
196
198
|
});
|
|
197
199
|
});
|
|
198
200
|
}
|
|
199
|
-
function transformEnv(styleObj, envKeyPaths) {
|
|
201
|
+
function transformEnv(styleObj, envKeyPaths, navigation) {
|
|
200
202
|
envKeyPaths.forEach((envKeyPath) => {
|
|
201
203
|
setStyle(styleObj, envKeyPath, ({ target, key, value }) => {
|
|
202
204
|
const parsed = parseFunc(value, 'env');
|
|
@@ -204,7 +206,7 @@ function transformEnv(styleObj, envKeyPaths) {
|
|
|
204
206
|
parsed.forEach(({ start, end, args }) => {
|
|
205
207
|
const name = args[0];
|
|
206
208
|
const fallback = args[1] || '';
|
|
207
|
-
const value = '' + (getSafeAreaInset(name) ?? global.__formatValue(fallback));
|
|
209
|
+
const value = '' + (getSafeAreaInset(name, navigation) ?? global.__formatValue(fallback));
|
|
208
210
|
replaced.replace(start, end - 1, value);
|
|
209
211
|
});
|
|
210
212
|
target[key] = global.__formatValue(replaced.source());
|
|
@@ -242,19 +244,27 @@ function transformStringify(styleObj) {
|
|
|
242
244
|
}
|
|
243
245
|
export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
244
246
|
const varStyle = {};
|
|
247
|
+
const unoVarStyle = {};
|
|
245
248
|
const normalStyle = {};
|
|
249
|
+
const normalStyleRef = useRef({});
|
|
250
|
+
const normalStyleChangedRef = useRef(false);
|
|
246
251
|
let hasVarDec = false;
|
|
247
252
|
let hasVarUse = false;
|
|
248
253
|
let hasSelfPercent = false;
|
|
249
254
|
const varKeyPaths = [];
|
|
255
|
+
const unoVarKeyPaths = [];
|
|
250
256
|
const percentKeyPaths = [];
|
|
251
257
|
const calcKeyPaths = [];
|
|
252
258
|
const envKeyPaths = [];
|
|
253
259
|
const [width, setWidth] = useState(0);
|
|
254
260
|
const [height, setHeight] = useState(0);
|
|
261
|
+
const navigation = useNavigation();
|
|
255
262
|
function varVisitor({ key, value, keyPath }) {
|
|
256
263
|
if (keyPath.length === 1) {
|
|
257
|
-
if (
|
|
264
|
+
if (unoVarDecRegExp.test(key)) {
|
|
265
|
+
unoVarStyle[key] = value;
|
|
266
|
+
}
|
|
267
|
+
else if (varDecRegExp.test(key)) {
|
|
258
268
|
hasVarDec = true;
|
|
259
269
|
varStyle[key] = value;
|
|
260
270
|
}
|
|
@@ -264,12 +274,18 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
264
274
|
}
|
|
265
275
|
}
|
|
266
276
|
// 对于var定义中使用的var无需替换值,可以通过resolveVar递归解析出值
|
|
267
|
-
if (!varDecRegExp.test(key)
|
|
268
|
-
|
|
269
|
-
|
|
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
|
+
}
|
|
270
286
|
}
|
|
271
287
|
}
|
|
272
|
-
// traverse var
|
|
288
|
+
// traverse var & generate normalStyle
|
|
273
289
|
traverseStyle(styleObj, [varVisitor]);
|
|
274
290
|
hasVarDec = hasVarDec || !!externalVarContext;
|
|
275
291
|
enableVar = enableVar || hasVarDec || hasVarUse;
|
|
@@ -277,78 +293,92 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
277
293
|
if (enableVarRef.current !== enableVar) {
|
|
278
294
|
error('css variable use/declare should be stable in the component lifecycle, or you can set [enable-var] with true.');
|
|
279
295
|
}
|
|
280
|
-
// apply var
|
|
296
|
+
// apply css var
|
|
281
297
|
const varContextRef = useRef({});
|
|
282
298
|
if (enableVarRef.current) {
|
|
299
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
283
300
|
const varContext = useContext(VarContext);
|
|
284
|
-
const newVarContext =
|
|
301
|
+
const newVarContext = extendObject({}, varContext, externalVarContext, varStyle);
|
|
285
302
|
// 缓存比较newVarContext是否发生变化
|
|
286
303
|
if (diffAndCloneA(varContextRef.current, newVarContext).diff) {
|
|
287
304
|
varContextRef.current = newVarContext;
|
|
288
305
|
}
|
|
289
306
|
transformVar(normalStyle, varKeyPaths, varContextRef.current);
|
|
290
307
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
308
|
+
// apply unocss var
|
|
309
|
+
if (unoVarKeyPaths.length) {
|
|
310
|
+
transformVar(normalStyle, unoVarKeyPaths, unoVarStyle);
|
|
295
311
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
312
|
+
const { clone, diff } = diffAndCloneA(normalStyle, normalStyleRef.current);
|
|
313
|
+
if (diff) {
|
|
314
|
+
normalStyleRef.current = clone;
|
|
315
|
+
normalStyleChangedRef.current = !normalStyleChangedRef.current;
|
|
300
316
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
+
}
|
|
305
323
|
}
|
|
306
|
-
|
|
307
|
-
|
|
324
|
+
function calcVisitor({ value, keyPath }) {
|
|
325
|
+
if (calcUseRegExp.test(value)) {
|
|
326
|
+
calcKeyPaths.push(keyPath.slice());
|
|
327
|
+
}
|
|
308
328
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
parentHeight,
|
|
318
|
-
parentFontSize
|
|
319
|
-
};
|
|
320
|
-
// apply env
|
|
321
|
-
transformEnv(normalStyle, envKeyPaths);
|
|
322
|
-
// apply percent
|
|
323
|
-
transformPercent(normalStyle, percentKeyPaths, percentConfig);
|
|
324
|
-
// apply calc
|
|
325
|
-
transformCalc(normalStyle, calcKeyPaths, (value, key) => {
|
|
326
|
-
if (PERCENT_REGEX.test(value)) {
|
|
327
|
-
const resolved = resolvePercent(value, key, percentConfig);
|
|
328
|
-
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
|
+
}
|
|
329
337
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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;
|
|
334
357
|
}
|
|
335
358
|
else {
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
}
|
|
338
367
|
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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({
|
|
346
377
|
hasVarDec,
|
|
347
|
-
enableVarRef,
|
|
348
378
|
varContextRef,
|
|
349
379
|
setWidth,
|
|
350
380
|
setHeight
|
|
351
|
-
};
|
|
381
|
+
}, memoResult);
|
|
352
382
|
}
|
|
353
383
|
export function traverseStyle(styleObj, visitors) {
|
|
354
384
|
const keyPath = [];
|
|
@@ -471,12 +501,12 @@ export const useStableCallback = (callback) => {
|
|
|
471
501
|
ref.current = callback;
|
|
472
502
|
return useCallback((...args) => ref.current?.(...args), []);
|
|
473
503
|
};
|
|
474
|
-
export
|
|
475
|
-
const ref = useRef(
|
|
504
|
+
export function usePrevious(value) {
|
|
505
|
+
const ref = useRef();
|
|
476
506
|
const prev = ref.current;
|
|
477
507
|
ref.current = value;
|
|
478
508
|
return prev;
|
|
479
|
-
}
|
|
509
|
+
}
|
|
480
510
|
export function flatGesture(gestures = []) {
|
|
481
511
|
return (gestures && gestures.flatMap((gesture) => {
|
|
482
512
|
if (gesture && gesture.nodeRefs) {
|
|
@@ -505,17 +535,20 @@ export function pickStyle(styleObj = {}, pickedKeys, callback) {
|
|
|
505
535
|
return acc;
|
|
506
536
|
}, {});
|
|
507
537
|
}
|
|
508
|
-
export function
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
throw new Error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.');
|
|
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.');
|
|
513
542
|
}
|
|
514
|
-
if (!
|
|
515
|
-
return {
|
|
543
|
+
if (!enableHoverRef.current)
|
|
544
|
+
return { isHover: false };
|
|
545
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
516
546
|
const gestureRef = useContext(ScrollViewContext).gestureRef;
|
|
547
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
517
548
|
const [isHover, setIsHover] = useState(false);
|
|
549
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
518
550
|
const dataRef = useRef({});
|
|
551
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
519
552
|
useEffect(() => {
|
|
520
553
|
return () => {
|
|
521
554
|
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
@@ -523,39 +556,39 @@ export function useHoverStyle({ hoverStyle, hoverStartTime, hoverStayTime, disab
|
|
|
523
556
|
};
|
|
524
557
|
}, []);
|
|
525
558
|
const setStartTimer = () => {
|
|
559
|
+
if (disabled)
|
|
560
|
+
return;
|
|
526
561
|
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
527
562
|
dataRef.current.startTimer = setTimeout(() => {
|
|
528
563
|
setIsHover(true);
|
|
529
564
|
}, +hoverStartTime);
|
|
530
565
|
};
|
|
531
566
|
const setStayTimer = () => {
|
|
567
|
+
if (disabled)
|
|
568
|
+
return;
|
|
532
569
|
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
|
|
533
570
|
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
534
571
|
dataRef.current.stayTimer = setTimeout(() => {
|
|
535
572
|
setIsHover(false);
|
|
536
573
|
}, +hoverStayTime);
|
|
537
574
|
};
|
|
575
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
538
576
|
const gesture = useMemo(() => {
|
|
539
577
|
return Gesture.Pan()
|
|
540
578
|
.onTouchesDown(() => {
|
|
541
579
|
'worklet';
|
|
542
|
-
if (disabled)
|
|
543
|
-
return;
|
|
544
580
|
runOnJS(setStartTimer)();
|
|
545
581
|
})
|
|
546
582
|
.onTouchesUp(() => {
|
|
547
583
|
'worklet';
|
|
548
|
-
if (disabled)
|
|
549
|
-
return;
|
|
550
584
|
runOnJS(setStayTimer)();
|
|
551
585
|
});
|
|
552
|
-
}, [
|
|
586
|
+
}, []);
|
|
553
587
|
if (gestureRef) {
|
|
554
588
|
gesture.simultaneousWithExternalGesture(gestureRef);
|
|
555
589
|
}
|
|
556
590
|
return {
|
|
557
591
|
isHover,
|
|
558
|
-
gesture
|
|
559
|
-
enableHoverStyle
|
|
592
|
+
gesture
|
|
560
593
|
};
|
|
561
594
|
}
|
|
@@ -2,31 +2,30 @@ interface EventConfig {
|
|
|
2
2
|
[key: string]: string[];
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
const eventConfigMap:
|
|
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
|