@imperosoft/cris-webui-components 1.1.3 → 1.1.4
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.mjs
CHANGED
|
@@ -102,6 +102,8 @@ function CrisButton({
|
|
|
102
102
|
const touchStartedHereRef = useRef(false);
|
|
103
103
|
const touchStartYRef = useRef(0);
|
|
104
104
|
const touchMovedRef = useRef(false);
|
|
105
|
+
const touchPressTimerRef = useRef(null);
|
|
106
|
+
const touchPressedRef = useRef(false);
|
|
105
107
|
const feedbackJoin = joinFeedback ?? join;
|
|
106
108
|
const feedback = useDigital(feedbackJoin ?? 0);
|
|
107
109
|
const enabledJoin = useDigital(joinEnable ?? 0);
|
|
@@ -125,6 +127,10 @@ function CrisButton({
|
|
|
125
127
|
}, [isVisible, join, smartId, dSet]);
|
|
126
128
|
useEffect(() => {
|
|
127
129
|
return () => {
|
|
130
|
+
if (touchPressTimerRef.current) {
|
|
131
|
+
clearTimeout(touchPressTimerRef.current);
|
|
132
|
+
touchPressTimerRef.current = null;
|
|
133
|
+
}
|
|
128
134
|
if (pressedRef.current && join != null && smartId == null) {
|
|
129
135
|
log("UNMOUNT RELEASE - component unmounting while pressed");
|
|
130
136
|
dSet(join, false);
|
|
@@ -185,40 +191,77 @@ function CrisButton({
|
|
|
185
191
|
}
|
|
186
192
|
};
|
|
187
193
|
const SCROLL_THRESHOLD = 8;
|
|
194
|
+
const PRESS_DELAY = 80;
|
|
195
|
+
const cancelPressTimer = () => {
|
|
196
|
+
if (touchPressTimerRef.current) {
|
|
197
|
+
clearTimeout(touchPressTimerRef.current);
|
|
198
|
+
touchPressTimerRef.current = null;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
188
201
|
const handleTouchStart = (e) => {
|
|
189
202
|
log("handleTouchStart");
|
|
190
203
|
touchStart();
|
|
191
204
|
touchingRef.current = true;
|
|
192
205
|
touchStartedHereRef.current = true;
|
|
193
206
|
touchMovedRef.current = false;
|
|
207
|
+
touchPressedRef.current = false;
|
|
194
208
|
touchStartYRef.current = e.touches[0]?.clientY ?? 0;
|
|
209
|
+
cancelPressTimer();
|
|
210
|
+
touchPressTimerRef.current = setTimeout(() => {
|
|
211
|
+
touchPressTimerRef.current = null;
|
|
212
|
+
if (touchStartedHereRef.current && !touchMovedRef.current) {
|
|
213
|
+
touchPressedRef.current = true;
|
|
214
|
+
handlePress();
|
|
215
|
+
log("delayed press fired");
|
|
216
|
+
}
|
|
217
|
+
}, PRESS_DELAY);
|
|
195
218
|
};
|
|
196
219
|
const handleTouchMove = (e) => {
|
|
197
220
|
if (touchMovedRef.current) return;
|
|
198
221
|
const dy = Math.abs((e.touches[0]?.clientY ?? 0) - touchStartYRef.current);
|
|
199
222
|
if (dy > SCROLL_THRESHOLD) {
|
|
200
223
|
touchMovedRef.current = true;
|
|
201
|
-
|
|
224
|
+
cancelPressTimer();
|
|
225
|
+
if (touchPressedRef.current) {
|
|
226
|
+
touchPressedRef.current = false;
|
|
227
|
+
handleRelease();
|
|
228
|
+
log("touchMove: scroll detected after press, releasing");
|
|
229
|
+
} else {
|
|
230
|
+
log("touchMove: scroll detected, press cancelled");
|
|
231
|
+
}
|
|
202
232
|
}
|
|
203
233
|
};
|
|
204
234
|
const handleTouchEnd = () => {
|
|
205
|
-
log("handleTouchEnd", {
|
|
235
|
+
log("handleTouchEnd", { started: touchStartedHereRef.current, moved: touchMovedRef.current, pressed: touchPressedRef.current });
|
|
236
|
+
cancelPressTimer();
|
|
206
237
|
touchEnd();
|
|
207
238
|
touchingRef.current = true;
|
|
208
|
-
if (touchStartedHereRef.current
|
|
239
|
+
if (!touchStartedHereRef.current || touchMovedRef.current) {
|
|
209
240
|
touchStartedHereRef.current = false;
|
|
210
|
-
|
|
241
|
+
touchPressedRef.current = false;
|
|
242
|
+
log("SKIPPED: touch moved or did not start here");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
touchStartedHereRef.current = false;
|
|
246
|
+
if (touchPressedRef.current) {
|
|
247
|
+
touchPressedRef.current = false;
|
|
211
248
|
handleRelease();
|
|
212
249
|
} else {
|
|
213
|
-
|
|
214
|
-
|
|
250
|
+
touchPressedRef.current = false;
|
|
251
|
+
handlePress();
|
|
252
|
+
handleRelease();
|
|
215
253
|
}
|
|
216
254
|
};
|
|
217
255
|
const handleTouchCancel = () => {
|
|
218
256
|
log("handleTouchCancel (scroll detected)");
|
|
257
|
+
cancelPressTimer();
|
|
219
258
|
touchEnd();
|
|
220
259
|
touchingRef.current = true;
|
|
221
260
|
touchStartedHereRef.current = false;
|
|
261
|
+
if (touchPressedRef.current) {
|
|
262
|
+
touchPressedRef.current = false;
|
|
263
|
+
handleRelease();
|
|
264
|
+
}
|
|
222
265
|
touchMovedRef.current = false;
|
|
223
266
|
};
|
|
224
267
|
const handleMouseDown = () => {
|