@ray-js/components 1.7.56-beta.6 → 1.7.56-beta.8
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/{Animated /index.d.ts → Animated/index.d.ts} +0 -7
- package/lib/{Animated /index.js → Animated/index.js} +124 -42
- package/lib/{Animated /native/ty-animated/index.js → Animated/native/ty-animated/index.js} +71 -74
- package/lib/{Animated /native/ty-animated/index.tyml → Animated/native/ty-animated/index.tyml} +6 -2
- package/lib/{Animated /types.d.ts → Animated/types.d.ts} +26 -22
- package/package.json +5 -5
- /package/lib/{Animated → Animated}/animation.d.ts +0 -0
- /package/lib/{Animated → Animated}/native/ty-animated/index.d.ts +0 -0
- /package/lib/{Animated → Animated}/native/ty-animated/index.json +0 -0
- /package/lib/{Animated → Animated}/native/ty-animated/index.tyss +0 -0
- /package/lib/{Animated → Animated}/types.js +0 -0
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Animated - 纯净底层动画组件
|
|
3
|
-
*
|
|
4
|
-
* 只提供三个核心方法:
|
|
5
|
-
* - setProperty(property, value): 设置动画属性
|
|
6
|
-
* - setStyle(style): 设置样式
|
|
7
|
-
* - setText(text): 设置文本内容
|
|
8
|
-
*
|
|
9
|
-
* 可以配合任何动画库使用(GSAP、Anime.js、Framer Motion 等)
|
|
10
3
|
*/
|
|
11
4
|
import React from 'react';
|
|
12
5
|
import type { AnimatedViewRef, AnimatedTextRef, AnimatedProps } from './types';
|
|
@@ -5,17 +5,11 @@ import "core-js/modules/esnext.iterator.constructor.js";
|
|
|
5
5
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
6
6
|
import "core-js/modules/esnext.iterator.map.js";
|
|
7
7
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
8
|
+
/* eslint-disable import/no-named-as-default */
|
|
8
9
|
/**
|
|
9
10
|
* Animated - 纯净底层动画组件
|
|
10
|
-
*
|
|
11
|
-
* 只提供三个核心方法:
|
|
12
|
-
* - setProperty(property, value): 设置动画属性
|
|
13
|
-
* - setStyle(style): 设置样式
|
|
14
|
-
* - setText(text): 设置文本内容
|
|
15
|
-
*
|
|
16
|
-
* 可以配合任何动画库使用(GSAP、Anime.js、Framer Motion 等)
|
|
17
11
|
*/
|
|
18
|
-
import React, { forwardRef, useImperativeHandle, useRef, useMemo, useCallback } from 'react';
|
|
12
|
+
import React, { forwardRef, useImperativeHandle, useRef, useMemo, useCallback, useEffect } from 'react';
|
|
19
13
|
import TyAnimatedComponent from './native/ty-animated';
|
|
20
14
|
|
|
21
15
|
// 小程序 API 声明
|
|
@@ -43,19 +37,40 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
43
37
|
mode = 'view',
|
|
44
38
|
onAnimationStart,
|
|
45
39
|
onAnimationEnd,
|
|
46
|
-
//
|
|
40
|
+
// 核心触摸事件
|
|
47
41
|
onClick,
|
|
48
42
|
onTouchStart,
|
|
49
43
|
onTouchEnd,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
onTouchMove,
|
|
45
|
+
onTouchCancel,
|
|
46
|
+
// onLongPress,
|
|
47
|
+
lockOnClick
|
|
48
|
+
// lockOnLongPress,
|
|
55
49
|
} = props;
|
|
56
|
-
|
|
50
|
+
|
|
51
|
+
// 使用队列管理多个 play() 的回调
|
|
52
|
+
// 因为基础库会触发多次 finish 事件(旧动画被打断 + 新动画完成)
|
|
53
|
+
// 当前动画的回调
|
|
54
|
+
// 同一时间只有一个动画在执行,新动画会打断旧动画
|
|
55
|
+
const currentCallbackRef = useRef(null);
|
|
57
56
|
const componentIdRef = useRef(id || "animated-".concat(Math.random().toString(36).slice(2, 11)));
|
|
58
57
|
|
|
58
|
+
// 组件卸载时清理未完成的动画 Promise
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
return () => {
|
|
61
|
+
const callback = currentCallbackRef.current;
|
|
62
|
+
if (callback) {
|
|
63
|
+
// console.log(`[Animated][${Date.now()}] 组件卸载,resolve 未完成的动画 Promise`)
|
|
64
|
+
callback({
|
|
65
|
+
detail: {
|
|
66
|
+
unmounted: true
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
currentCallbackRef.current = null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
59
74
|
// 提取文本内容(当 mode='text' 时)
|
|
60
75
|
const textContent = useMemo(() => {
|
|
61
76
|
if (mode !== 'text' || !children) return undefined;
|
|
@@ -90,13 +105,12 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
90
105
|
* ref.current.setStyle({ color: 'red', fontSize: '16px', border: '1px solid #ccc' })
|
|
91
106
|
*/
|
|
92
107
|
setStyle(styleValue, callback) {
|
|
93
|
-
return new Promise(resolve => {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
94
109
|
var _inst$setCustomStyle;
|
|
95
110
|
const inst = getDomInstance();
|
|
96
111
|
if (!inst) {
|
|
97
112
|
console.warn('No DOM instance found');
|
|
98
|
-
|
|
99
|
-
if (callback) callback();
|
|
113
|
+
reject();
|
|
100
114
|
return;
|
|
101
115
|
}
|
|
102
116
|
|
|
@@ -115,6 +129,19 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
115
129
|
return;
|
|
116
130
|
}
|
|
117
131
|
|
|
132
|
+
// 如果有动画在执行,setStyle 会清空 transition,打断动画
|
|
133
|
+
// 主动 resolve 当前 Promise
|
|
134
|
+
const animCallback = currentCallbackRef.current;
|
|
135
|
+
if (animCallback) {
|
|
136
|
+
console.log("[Animated][".concat(Date.now(), "] setStyle \u6253\u65AD\u52A8\u753B\uFF0Cresolve Promise"));
|
|
137
|
+
animCallback({
|
|
138
|
+
detail: {
|
|
139
|
+
interruptedBySetStyle: true
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
currentCallbackRef.current = null;
|
|
143
|
+
}
|
|
144
|
+
|
|
118
145
|
// setData 完成后的回调
|
|
119
146
|
(_inst$setCustomStyle = inst.setCustomStyle) === null || _inst$setCustomStyle === void 0 || _inst$setCustomStyle.call(inst, styleString, () => {
|
|
120
147
|
// 调用用户回调
|
|
@@ -198,14 +225,23 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
198
225
|
animation.play = () => {
|
|
199
226
|
return new Promise(resolve => {
|
|
200
227
|
var _inst$__applyAnimData;
|
|
201
|
-
//
|
|
202
|
-
const
|
|
228
|
+
// 如果有旧的 Promise,主动 resolve 它(被新动画打断)
|
|
229
|
+
const oldCallback = currentCallbackRef.current;
|
|
230
|
+
if (oldCallback) {
|
|
231
|
+
console.log("[Animated][".concat(Date.now(), "] \u65B0\u52A8\u753B\u5F00\u59CB\uFF0C\u628A\u4E4B\u524D\u7684\u52A8\u753B\u7ED9\u4E2D\u65AD\u6389"));
|
|
232
|
+
oldCallback({
|
|
233
|
+
detail: {
|
|
234
|
+
interrupted: true
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
203
238
|
|
|
204
|
-
//
|
|
239
|
+
// 保存新的 callback
|
|
240
|
+
currentCallbackRef.current = resolve;
|
|
241
|
+
console.log("[Animated][".concat(Date.now(), "] play() \u8C03\u7528"));
|
|
205
242
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
243
|
+
// 导出动画数据
|
|
244
|
+
const animationData = animation.export();
|
|
209
245
|
(_inst$__applyAnimData = inst.__applyAnimData) === null || _inst$__applyAnimData === void 0 || _inst$__applyAnimData.call(inst, animationData);
|
|
210
246
|
});
|
|
211
247
|
};
|
|
@@ -306,22 +342,73 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
306
342
|
// 处理 customStyle,避免传入 undefined
|
|
307
343
|
const customStyleValue = useMemo(() => {
|
|
308
344
|
if (!style) return undefined;
|
|
345
|
+
console.log('customStyle', style, typeof style === 'object' ? styleToString(style) : style);
|
|
309
346
|
return typeof style === 'object' ? styleToString(style) : style;
|
|
310
|
-
}, []);
|
|
347
|
+
}, [style]);
|
|
311
348
|
const handleAnimationEnd = useCallback(event => {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
349
|
+
const callback = currentCallbackRef.current;
|
|
350
|
+
if (callback) {
|
|
351
|
+
callback(event);
|
|
352
|
+
currentCallbackRef.current = null;
|
|
316
353
|
}
|
|
317
354
|
if (onAnimationEnd) {
|
|
318
355
|
onAnimationEnd();
|
|
319
356
|
}
|
|
320
|
-
}, [onAnimationEnd
|
|
357
|
+
}, [onAnimationEnd]);
|
|
358
|
+
|
|
359
|
+
// 包装 onClick,如果启用了 lockOnClick
|
|
360
|
+
const wrappedOnClick = useMemo(() => {
|
|
361
|
+
console.log('wrappedOnClick', !!onClick);
|
|
362
|
+
if (!onClick) return undefined;
|
|
363
|
+
if (lockOnClick) {
|
|
364
|
+
// 声明式锁:包装 onClick,完成后通过 setData 触发解锁
|
|
365
|
+
return async event => {
|
|
366
|
+
const startTime = Date.now();
|
|
367
|
+
console.log("[Animated.React][".concat(startTime, "] \uD83C\uDFAF onClick \u5F00\u59CB\u6267\u884C"));
|
|
368
|
+
try {
|
|
369
|
+
await onClick(event);
|
|
370
|
+
// console.log(
|
|
371
|
+
// `[Animated.React][${Date.now()}] onClick 执行完成,耗时: ${Date.now() - startTime}ms`
|
|
372
|
+
// )
|
|
373
|
+
} catch (error) {
|
|
374
|
+
console.error("[Animated.React][".concat(Date.now(), "] onClick \u6267\u884C\u5931\u8D25:"), error);
|
|
375
|
+
throw error;
|
|
376
|
+
} finally {
|
|
377
|
+
// 等待事件执行完成,自动解锁
|
|
378
|
+
await new Promise(resolve => {
|
|
379
|
+
const inst = getDomInstance();
|
|
380
|
+
inst.__unlockEvent('click', resolve);
|
|
381
|
+
});
|
|
382
|
+
// console.log('click 已解锁')
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
return onClick;
|
|
387
|
+
}, [onClick, lockOnClick]);
|
|
388
|
+
|
|
389
|
+
// 自动检测哪些事件需要加锁
|
|
390
|
+
const autoLockEvents = useMemo(() => {
|
|
391
|
+
const events = [];
|
|
392
|
+
|
|
393
|
+
// 通过 prop 声明
|
|
394
|
+
if (lockOnClick) {
|
|
395
|
+
events.push('click');
|
|
396
|
+
}
|
|
397
|
+
// if (lockOnLongPress) {
|
|
398
|
+
// events.push('longPress')
|
|
399
|
+
// }
|
|
400
|
+
|
|
401
|
+
if (events.length > 0) {
|
|
402
|
+
console.log("[Animated][".concat(Date.now(), "] \u81EA\u52A8\u52A0\u9501\u4E8B\u4EF6:"), events);
|
|
403
|
+
}
|
|
404
|
+
return events;
|
|
405
|
+
}, [onClick, lockOnClick]);
|
|
321
406
|
const eventBindings = {};
|
|
322
|
-
if (
|
|
407
|
+
if (wrappedOnClick) eventBindings['bind:click'] = wrappedOnClick;
|
|
323
408
|
if (onTouchStart) eventBindings['bind:touchstart'] = onTouchStart;
|
|
324
409
|
if (onTouchEnd) eventBindings['bind:touchend'] = onTouchEnd;
|
|
410
|
+
if (onTouchMove) eventBindings['bind:touchmove'] = onTouchMove;
|
|
411
|
+
if (onTouchCancel) eventBindings['bind:touchcancel'] = onTouchCancel;
|
|
325
412
|
if (onAnimationStart) eventBindings['bind:animationbegin'] = onAnimationStart;
|
|
326
413
|
eventBindings['bind:animationfinish'] = handleAnimationEnd;
|
|
327
414
|
return (
|
|
@@ -329,22 +416,17 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
329
416
|
// @ts-ignore - 小程序自定义组件
|
|
330
417
|
React.createElement(TyAnimatedComponent, _extends({
|
|
331
418
|
id: componentIdRef.current,
|
|
332
|
-
__mode: mode
|
|
419
|
+
__mode: mode,
|
|
420
|
+
__componentId: componentIdRef.current
|
|
333
421
|
}, className ? {
|
|
334
422
|
__className: className
|
|
335
423
|
} : {}, customStyleValue ? {
|
|
336
424
|
__style: customStyleValue
|
|
337
425
|
} : {}, mode === 'text' && textContent !== undefined ? {
|
|
338
426
|
__text: textContent
|
|
339
|
-
} : {},
|
|
340
|
-
|
|
341
|
-
} :
|
|
342
|
-
__throttleClick: throttleClick
|
|
343
|
-
} : {}, throttleTouchStart !== undefined ? {
|
|
344
|
-
__throttleTouchStart: throttleTouchStart
|
|
345
|
-
} : {}, throttleTouchEnd !== undefined ? {
|
|
346
|
-
__throttleTouchEnd: throttleTouchEnd
|
|
347
|
-
} : {}, eventBindings), mode === 'view' ? children : null)
|
|
427
|
+
} : {}, autoLockEvents ? {
|
|
428
|
+
__autoLockEvents: autoLockEvents
|
|
429
|
+
} : [], eventBindings), mode === 'view' ? children : null)
|
|
348
430
|
);
|
|
349
431
|
});
|
|
350
432
|
AnimatedBase.displayName = 'AnimatedBase';
|
|
@@ -376,4 +458,4 @@ const Animated = {
|
|
|
376
458
|
};
|
|
377
459
|
export default Animated;
|
|
378
460
|
|
|
379
|
-
//
|
|
461
|
+
// 导出类型和工具函数
|
|
@@ -37,24 +37,6 @@ Component({
|
|
|
37
37
|
onAnimationEnd: {
|
|
38
38
|
type: null,
|
|
39
39
|
value: null
|
|
40
|
-
},
|
|
41
|
-
// 统一的事件节流时间(毫秒)
|
|
42
|
-
__throttle: {
|
|
43
|
-
type: Number,
|
|
44
|
-
value: 0
|
|
45
|
-
},
|
|
46
|
-
// 各事件独立的节流时间(毫秒),优先级高于 __throttle
|
|
47
|
-
__throttleClick: {
|
|
48
|
-
type: Number,
|
|
49
|
-
value: 0
|
|
50
|
-
},
|
|
51
|
-
__throttleTouchStart: {
|
|
52
|
-
type: Number,
|
|
53
|
-
value: 0
|
|
54
|
-
},
|
|
55
|
-
__throttleTouchEnd: {
|
|
56
|
-
type: Number,
|
|
57
|
-
value: 0
|
|
58
40
|
}
|
|
59
41
|
},
|
|
60
42
|
// 定义外部事件
|
|
@@ -63,29 +45,42 @@ Component({
|
|
|
63
45
|
__text: '',
|
|
64
46
|
__style: '',
|
|
65
47
|
__className: '',
|
|
66
|
-
__animData: null
|
|
67
|
-
// 动画数据
|
|
68
|
-
// 记录各事件的最后触发时间
|
|
69
|
-
__lastClickTime: 0,
|
|
70
|
-
__lastTouchStartTime: 0,
|
|
71
|
-
__lastTouchEndTime: 0
|
|
48
|
+
__animData: null // 动画数据
|
|
72
49
|
},
|
|
73
50
|
lifetimes: {
|
|
74
51
|
attached() {
|
|
75
|
-
//
|
|
52
|
+
// 初始化
|
|
53
|
+
// 为每个事件类型维护独立的锁
|
|
54
|
+
this._locks = {};
|
|
55
|
+
this._componentId = this.data.__componentId || this.id;
|
|
56
|
+
this._excludedTouchStartIdentifier = new Set();
|
|
76
57
|
},
|
|
77
58
|
detached() {
|
|
78
|
-
//
|
|
59
|
+
//
|
|
79
60
|
}
|
|
80
61
|
},
|
|
81
62
|
methods: {
|
|
63
|
+
/**
|
|
64
|
+
* 原生层事件锁:解锁(支持指定事件类型)
|
|
65
|
+
* @param eventType - 事件类型,如 'click', 'longPress'
|
|
66
|
+
* @param resolve - Promise resolve 函数
|
|
67
|
+
*/
|
|
68
|
+
__unlockEvent(eventType, resolve) {
|
|
69
|
+
if (!eventType) {
|
|
70
|
+
console.warn('[TyAnimated] __unlockEvent: eventType is required');
|
|
71
|
+
resolve();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 清除内部事件锁状态
|
|
76
|
+
this._locks[eventType] = false;
|
|
77
|
+
resolve();
|
|
78
|
+
},
|
|
82
79
|
/**
|
|
83
80
|
* 事件处理器
|
|
84
81
|
*/
|
|
85
82
|
__handleTiggerEvent(eventName, e) {
|
|
86
83
|
// 触发自定义事件,让外部可以监听
|
|
87
|
-
// bubbles: false - 不在 React 层冒泡,避免与原生层冒泡重复
|
|
88
|
-
// 原生层的 bindtap 会自然冒泡,并经过每个组件的节流检查
|
|
89
84
|
this.triggerEvent(eventName, e, {
|
|
90
85
|
bubbles: false,
|
|
91
86
|
composed: true
|
|
@@ -157,6 +152,8 @@ Component({
|
|
|
157
152
|
|
|
158
153
|
// 合并样式
|
|
159
154
|
const currentStyle = this._parseStyle(this.data.__style || '');
|
|
155
|
+
console.log('_style', this.data.__style);
|
|
156
|
+
console.log('currentStyle', currentStyle);
|
|
160
157
|
const newStyle = this._parseStyle(value);
|
|
161
158
|
const mergedStyle = _objectSpread(_objectSpread({}, currentStyle), newStyle);
|
|
162
159
|
let mergedStyleString = this._styleToString(mergedStyle);
|
|
@@ -164,11 +161,8 @@ Component({
|
|
|
164
161
|
// 添加一个不影响渲染的注释,使样式字符串不同
|
|
165
162
|
mergedStyleString = "".concat(mergedStyleString, ";/* ").concat(Date.now(), " */");
|
|
166
163
|
}
|
|
167
|
-
|
|
168
|
-
// 一次性 setData,不嵌套
|
|
169
164
|
this.setData({
|
|
170
|
-
__style: mergedStyleString
|
|
171
|
-
__animData: null // 总是清空动画数据
|
|
165
|
+
__style: mergedStyleString
|
|
172
166
|
}, () => {
|
|
173
167
|
if (callback) callback();
|
|
174
168
|
});
|
|
@@ -220,54 +214,57 @@ Component({
|
|
|
220
214
|
__animData: animData
|
|
221
215
|
});
|
|
222
216
|
},
|
|
223
|
-
// 核心触摸事件处理(只保留最常用的)
|
|
224
|
-
__onClick(e) {
|
|
225
|
-
// 节流判断:优先使用具体事件的节流时间,否则使用统一的节流时间
|
|
226
|
-
const throttleTime = this.properties.__throttleClick || this.properties.__throttle;
|
|
227
|
-
if (throttleTime > 0) {
|
|
228
|
-
const now = Date.now();
|
|
229
|
-
const lastTime = this.data.__lastClickTime;
|
|
230
|
-
if (now - lastTime < throttleTime) {
|
|
231
|
-
console.log("[TyAnimated][".concat(now, "] __onClick \u88AB\u8282\u6D41\u5FFD\u7565\uFF0C\u8DDD\u4E0A\u6B21\u89E6\u53D1 ").concat(now - lastTime, "ms < ").concat(throttleTime, "ms"));
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
this.setData({
|
|
235
|
-
__lastClickTime: now
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
this.__handleTiggerEvent('click', e);
|
|
239
|
-
},
|
|
240
217
|
__onTouchStart(e) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
218
|
+
/**
|
|
219
|
+
* 因为end事件会合成tap事件的原因,可能会出现
|
|
220
|
+
* click -> lock -> 执行内部逻辑 ---- 过程中可能会有touchstart事件(identifier: 1) -> unlock -> click完成 -> touchend(identifier: 1) -> 合成了tap -> click(额外的异常点击)
|
|
221
|
+
* 逻辑层的锁 锁不住视图层的事件监听
|
|
222
|
+
*
|
|
223
|
+
* 方案:将在click事件锁住后的所有touchStart保存起来,在tap的时候对比set中是否有相同的序列id,有的话就直接return,并重置set
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
// 只有在锁住的状态下存储 touchStart 的序列值
|
|
227
|
+
if (this._locks['click']) {
|
|
228
|
+
const touchId = e.touches[0].identifier; // 每个触摸序列的唯一ID
|
|
229
|
+
// console.log('------1-1--1-1-1-1-:::', touchId)
|
|
230
|
+
this._excludedTouchStartIdentifier.add(touchId);
|
|
253
231
|
}
|
|
254
232
|
this.__handleTiggerEvent('touchstart', e);
|
|
255
233
|
},
|
|
234
|
+
__onTouchMove(e) {
|
|
235
|
+
this.__handleTiggerEvent('touchmove', e);
|
|
236
|
+
},
|
|
256
237
|
__onTouchEnd(e) {
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
if (throttleTime > 0) {
|
|
260
|
-
const now = Date.now();
|
|
261
|
-
const lastTime = this.data.__lastTouchEndTime;
|
|
262
|
-
if (now - lastTime < throttleTime) {
|
|
263
|
-
console.log("[TyAnimated][".concat(now, "] __onTouchEnd \u88AB\u8282\u6D41\u5FFD\u7565\uFF0C\u8DDD\u4E0A\u6B21\u89E6\u53D1 ").concat(now - lastTime, "ms < ").concat(throttleTime, "ms"));
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
this.setData({
|
|
267
|
-
__lastTouchEndTime: now
|
|
268
|
-
});
|
|
269
|
-
}
|
|
238
|
+
// console.log('=====2---22-2-2-::::', e.changedTouches[0].identifier)
|
|
239
|
+
|
|
270
240
|
this.__handleTiggerEvent('touchend', e);
|
|
241
|
+
},
|
|
242
|
+
__onTouchCancel(e) {
|
|
243
|
+
this.__handleTiggerEvent('touchcancel', e);
|
|
244
|
+
},
|
|
245
|
+
// 核心触摸事件处理(只保留最常用的)
|
|
246
|
+
__onClick(e) {
|
|
247
|
+
Date.now();
|
|
248
|
+
const eventType = 'click';
|
|
249
|
+
// console.log('---3----3-3--:::', e.changedTouches[0].identifier)
|
|
250
|
+
// 对比set中是否有相同的序列id,有的话就直接return,并重置set
|
|
251
|
+
e.changedTouches[0].identifier;
|
|
252
|
+
const isExceptiontrigger = this._excludedTouchStartIdentifier.has(e.changedTouches[0].identifier);
|
|
253
|
+
if (isExceptiontrigger) {
|
|
254
|
+
this._excludedTouchStartIdentifier.clear();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 检查该事件类型是否已加锁,锁住直接return
|
|
259
|
+
if (this._locks[eventType]) {
|
|
260
|
+
// console.log(`[TyAnimated][${now}] ⚠️ 事件被锁拦截: ${eventType}`)
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
// 如果发现click事件需要自动开解锁,在第一次click的时候就自动加上锁
|
|
264
|
+
if (this.data.__autoLockEvents.includes(eventType)) {
|
|
265
|
+
this._locks[eventType] = true;
|
|
266
|
+
}
|
|
267
|
+
this.__handleTiggerEvent(eventType, e);
|
|
271
268
|
}
|
|
272
269
|
}
|
|
273
270
|
});
|
package/lib/{Animated /native/ty-animated/index.tyml → Animated/native/ty-animated/index.tyml}
RENAMED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
class="{{__className}}"
|
|
6
6
|
style="{{__style}}"
|
|
7
7
|
animation="{{__animData}}"
|
|
8
|
-
bindtap="__onClick"
|
|
9
8
|
bindtouchstart="__onTouchStart"
|
|
10
9
|
bindtouchend="__onTouchEnd"
|
|
10
|
+
bindtouchmove="__onTouchMove"
|
|
11
|
+
bindtouchcancel="__onTouchCancel"
|
|
12
|
+
bindtap="__onClick"
|
|
11
13
|
>
|
|
12
14
|
<slot></slot>
|
|
13
15
|
</view>
|
|
@@ -17,9 +19,11 @@
|
|
|
17
19
|
class="container {{__className}}"
|
|
18
20
|
style="{{__style}}"
|
|
19
21
|
animation="{{__animData}}"
|
|
20
|
-
bindtap="__onClick"
|
|
21
22
|
bindtouchstart="__onTouchStart"
|
|
22
23
|
bindtouchend="__onTouchEnd"
|
|
24
|
+
bindtouchmove="__onTouchMove"
|
|
25
|
+
bindtouchcancel="__onTouchCancel"
|
|
26
|
+
bindtap="__onClick"
|
|
23
27
|
>{{__text}}</text>
|
|
24
28
|
</block>
|
|
25
29
|
|
|
@@ -2,32 +2,14 @@ import type React from 'react';
|
|
|
2
2
|
/**
|
|
3
3
|
* 触摸事件处理器(只保留核心事件)
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* 如需其他事件(如 onLongPress, onTouchMove 等),请在 Animated 的子元素上直接绑定
|
|
5
|
+
* 注:只提供最常用的事件 (onClick)
|
|
7
6
|
*/
|
|
8
7
|
export interface TouchEventHandler {
|
|
9
8
|
onClick?: (e: TouchEvent) => any;
|
|
10
9
|
onTouchStart?: (e: TouchEvent) => any;
|
|
11
10
|
onTouchEnd?: (e: TouchEvent) => any;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* 优先级:throttleClick/throttleTouchStart/throttleTouchEnd > throttle
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* <Animated.View throttle={300} onClick={...} onTouchStart={...} />
|
|
18
|
-
*/
|
|
19
|
-
throttle?: number;
|
|
20
|
-
/**
|
|
21
|
-
* click 事件节流时间(毫秒),优先级高于 throttle
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* <Animated.View throttle={300} throttleClick={500} onClick={...} />
|
|
25
|
-
*/
|
|
26
|
-
throttleClick?: number;
|
|
27
|
-
/** touchstart 事件节流时间(毫秒),优先级高于 throttle */
|
|
28
|
-
throttleTouchStart?: number;
|
|
29
|
-
/** touchend 事件节流时间(毫秒),优先级高于 throttle */
|
|
30
|
-
throttleTouchEnd?: number;
|
|
11
|
+
onTouchMove?: (e: TouchEvent) => any;
|
|
12
|
+
onTouchCancel?: (e: TouchEvent) => any;
|
|
31
13
|
}
|
|
32
14
|
interface TargetType {
|
|
33
15
|
id: string;
|
|
@@ -187,7 +169,13 @@ export interface AnimatedViewRef {
|
|
|
187
169
|
* ```
|
|
188
170
|
*/
|
|
189
171
|
animate: (options?: TOptions) => IAnimation & {
|
|
190
|
-
play(): Promise<
|
|
172
|
+
play(): Promise<{
|
|
173
|
+
detail?: {
|
|
174
|
+
interruptedBySetStyle?: boolean;
|
|
175
|
+
interrupted?: boolean;
|
|
176
|
+
};
|
|
177
|
+
[key: string]: any;
|
|
178
|
+
}>;
|
|
191
179
|
};
|
|
192
180
|
/**
|
|
193
181
|
* 获取元素的布局位置和尺寸信息
|
|
@@ -327,5 +315,21 @@ export interface AnimatedProps extends TouchEventHandler {
|
|
|
327
315
|
onAnimationStart?: () => void;
|
|
328
316
|
/** 动画结束回调 */
|
|
329
317
|
onAnimationEnd?: () => void;
|
|
318
|
+
/**
|
|
319
|
+
* 点击事件自动加锁
|
|
320
|
+
* 防止快速点击导致的重复触发
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```tsx
|
|
324
|
+
* <Animated.View
|
|
325
|
+
* ref={ref}
|
|
326
|
+
* onClick={async () => {
|
|
327
|
+
* await doSomething()
|
|
328
|
+
* }}
|
|
329
|
+
* lockOnClick // 自动加锁,回调执行完自动解锁
|
|
330
|
+
* />
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
lockOnClick?: boolean;
|
|
330
334
|
}
|
|
331
335
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/components",
|
|
3
|
-
"version": "1.7.56-beta.
|
|
3
|
+
"version": "1.7.56-beta.8",
|
|
4
4
|
"description": "Ray basic components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ray-core/macro": "^0.4.9",
|
|
31
31
|
"@ray-core/wechat": "^0.4.9",
|
|
32
|
-
"@ray-js/adapter": "1.7.56-beta.
|
|
33
|
-
"@ray-js/framework-shared": "1.7.56-beta.
|
|
32
|
+
"@ray-js/adapter": "1.7.56-beta.8",
|
|
33
|
+
"@ray-js/framework-shared": "1.7.56-beta.8",
|
|
34
34
|
"ahooks": "^3.8.5",
|
|
35
35
|
"clsx": "^1.2.1",
|
|
36
36
|
"core-js": "^3.43.0",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"style-to-object": "^0.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@ray-js/cli": "1.7.56-beta.
|
|
43
|
+
"@ray-js/cli": "1.7.56-beta.8"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public",
|
|
47
47
|
"registry": "https://registry.npmjs.org"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "8f42d569ceece3840cdbf9aa4a223abcd06b0915"
|
|
50
50
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|