@imperosoft/cris-webui-components 1.1.3 → 1.1.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +49 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -141,6 +141,8 @@ function CrisButton({
|
|
|
141
141
|
const touchStartedHereRef = (0, import_react.useRef)(false);
|
|
142
142
|
const touchStartYRef = (0, import_react.useRef)(0);
|
|
143
143
|
const touchMovedRef = (0, import_react.useRef)(false);
|
|
144
|
+
const touchPressTimerRef = (0, import_react.useRef)(null);
|
|
145
|
+
const touchPressedRef = (0, import_react.useRef)(false);
|
|
144
146
|
const feedbackJoin = joinFeedback ?? join;
|
|
145
147
|
const feedback = (0, import_cris_webui_ch5_core.useDigital)(feedbackJoin ?? 0);
|
|
146
148
|
const enabledJoin = (0, import_cris_webui_ch5_core.useDigital)(joinEnable ?? 0);
|
|
@@ -164,6 +166,10 @@ function CrisButton({
|
|
|
164
166
|
}, [isVisible, join, smartId, dSet]);
|
|
165
167
|
(0, import_react.useEffect)(() => {
|
|
166
168
|
return () => {
|
|
169
|
+
if (touchPressTimerRef.current) {
|
|
170
|
+
clearTimeout(touchPressTimerRef.current);
|
|
171
|
+
touchPressTimerRef.current = null;
|
|
172
|
+
}
|
|
167
173
|
if (pressedRef.current && join != null && smartId == null) {
|
|
168
174
|
log("UNMOUNT RELEASE - component unmounting while pressed");
|
|
169
175
|
dSet(join, false);
|
|
@@ -224,40 +230,77 @@ function CrisButton({
|
|
|
224
230
|
}
|
|
225
231
|
};
|
|
226
232
|
const SCROLL_THRESHOLD = 8;
|
|
233
|
+
const PRESS_DELAY = 80;
|
|
234
|
+
const cancelPressTimer = () => {
|
|
235
|
+
if (touchPressTimerRef.current) {
|
|
236
|
+
clearTimeout(touchPressTimerRef.current);
|
|
237
|
+
touchPressTimerRef.current = null;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
227
240
|
const handleTouchStart = (e) => {
|
|
228
241
|
log("handleTouchStart");
|
|
229
242
|
touchStart();
|
|
230
243
|
touchingRef.current = true;
|
|
231
244
|
touchStartedHereRef.current = true;
|
|
232
245
|
touchMovedRef.current = false;
|
|
246
|
+
touchPressedRef.current = false;
|
|
233
247
|
touchStartYRef.current = e.touches[0]?.clientY ?? 0;
|
|
248
|
+
cancelPressTimer();
|
|
249
|
+
touchPressTimerRef.current = setTimeout(() => {
|
|
250
|
+
touchPressTimerRef.current = null;
|
|
251
|
+
if (touchStartedHereRef.current && !touchMovedRef.current) {
|
|
252
|
+
touchPressedRef.current = true;
|
|
253
|
+
handlePress();
|
|
254
|
+
log("delayed press fired");
|
|
255
|
+
}
|
|
256
|
+
}, PRESS_DELAY);
|
|
234
257
|
};
|
|
235
258
|
const handleTouchMove = (e) => {
|
|
236
259
|
if (touchMovedRef.current) return;
|
|
237
260
|
const dy = Math.abs((e.touches[0]?.clientY ?? 0) - touchStartYRef.current);
|
|
238
261
|
if (dy > SCROLL_THRESHOLD) {
|
|
239
262
|
touchMovedRef.current = true;
|
|
240
|
-
|
|
263
|
+
cancelPressTimer();
|
|
264
|
+
if (touchPressedRef.current) {
|
|
265
|
+
touchPressedRef.current = false;
|
|
266
|
+
handleRelease();
|
|
267
|
+
log("touchMove: scroll detected after press, releasing");
|
|
268
|
+
} else {
|
|
269
|
+
log("touchMove: scroll detected, press cancelled");
|
|
270
|
+
}
|
|
241
271
|
}
|
|
242
272
|
};
|
|
243
273
|
const handleTouchEnd = () => {
|
|
244
|
-
log("handleTouchEnd", {
|
|
274
|
+
log("handleTouchEnd", { started: touchStartedHereRef.current, moved: touchMovedRef.current, pressed: touchPressedRef.current });
|
|
275
|
+
cancelPressTimer();
|
|
245
276
|
touchEnd();
|
|
246
277
|
touchingRef.current = true;
|
|
247
|
-
if (touchStartedHereRef.current
|
|
278
|
+
if (!touchStartedHereRef.current || touchMovedRef.current) {
|
|
248
279
|
touchStartedHereRef.current = false;
|
|
249
|
-
|
|
280
|
+
touchPressedRef.current = false;
|
|
281
|
+
log("SKIPPED: touch moved or did not start here");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
touchStartedHereRef.current = false;
|
|
285
|
+
if (touchPressedRef.current) {
|
|
286
|
+
touchPressedRef.current = false;
|
|
250
287
|
handleRelease();
|
|
251
288
|
} else {
|
|
252
|
-
|
|
253
|
-
|
|
289
|
+
touchPressedRef.current = false;
|
|
290
|
+
handlePress();
|
|
291
|
+
handleRelease();
|
|
254
292
|
}
|
|
255
293
|
};
|
|
256
294
|
const handleTouchCancel = () => {
|
|
257
295
|
log("handleTouchCancel (scroll detected)");
|
|
296
|
+
cancelPressTimer();
|
|
258
297
|
touchEnd();
|
|
259
298
|
touchingRef.current = true;
|
|
260
299
|
touchStartedHereRef.current = false;
|
|
300
|
+
if (touchPressedRef.current) {
|
|
301
|
+
touchPressedRef.current = false;
|
|
302
|
+
handleRelease();
|
|
303
|
+
}
|
|
261
304
|
touchMovedRef.current = false;
|
|
262
305
|
};
|
|
263
306
|
const handleMouseDown = () => {
|