UNPKG

@tamagui/react-native-web-lite

Version:
117 lines (116 loc) 4.54 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var TouchHistoryMath_exports = {}; __export(TouchHistoryMath_exports, { default: () => TouchHistoryMath_default }); module.exports = __toCommonJS(TouchHistoryMath_exports); var TouchHistoryMath = { /** * This code is optimized and not intended to look beautiful. This allows * computing of touch centroids that have moved after `touchesChangedAfter` * timeStamp. You can compute the current centroid involving all touches * moves after `touchesChangedAfter`, or you can compute the previous * centroid of all touches that were moved after `touchesChangedAfter`. * * @param {TouchHistoryMath} touchHistory Standard Responder touch track * data. * @param {number} touchesChangedAfter timeStamp after which moved touches * are considered "actively moving" - not just "active". * @param {boolean} isXAxis Consider `x` dimension vs. `y` dimension. * @param {boolean} ofCurrent Compute current centroid for actively moving * touches vs. previous centroid of now actively moving touches. * @return {number} value of centroid in specified dimension. */ centroidDimension: function(touchHistory, touchesChangedAfter, isXAxis, ofCurrent) { var touchBank = touchHistory.touchBank, total = 0, count = 0, oneTouchData = touchHistory.numberActiveTouches === 1 ? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch] : null; if (oneTouchData !== null) oneTouchData.touchActive && oneTouchData.currentTimeStamp > touchesChangedAfter && (total += ofCurrent && isXAxis ? oneTouchData.currentPageX : ofCurrent && !isXAxis ? oneTouchData.currentPageY : !ofCurrent && isXAxis ? oneTouchData.previousPageX : oneTouchData.previousPageY, count = 1); else for (var i = 0; i < touchBank.length; i++) { var touchTrack = touchBank[i]; if (touchTrack != null && touchTrack.touchActive && touchTrack.currentTimeStamp >= touchesChangedAfter) { var toAdd = void 0; ofCurrent && isXAxis ? toAdd = touchTrack.currentPageX : ofCurrent && !isXAxis ? toAdd = touchTrack.currentPageY : !ofCurrent && isXAxis ? toAdd = touchTrack.previousPageX : toAdd = touchTrack.previousPageY, total += toAdd, count++; } } return count > 0 ? total / count : TouchHistoryMath.noCentroid; }, currentCentroidXOfTouchesChangedAfter: function(touchHistory, touchesChangedAfter) { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, !0, // isXAxis !0 ); }, // ofCurrent currentCentroidYOfTouchesChangedAfter: function(touchHistory, touchesChangedAfter) { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, !1, // isXAxis !0 ); }, // ofCurrent previousCentroidXOfTouchesChangedAfter: function(touchHistory, touchesChangedAfter) { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, !0, // isXAxis !1 ); }, // ofCurrent previousCentroidYOfTouchesChangedAfter: function(touchHistory, touchesChangedAfter) { return TouchHistoryMath.centroidDimension( touchHistory, touchesChangedAfter, !1, // isXAxis !1 ); }, // ofCurrent currentCentroidX: function(touchHistory) { return TouchHistoryMath.centroidDimension( touchHistory, 0, // touchesChangedAfter !0, // isXAxis !0 ); }, // ofCurrent currentCentroidY: function(touchHistory) { return TouchHistoryMath.centroidDimension( touchHistory, 0, // touchesChangedAfter !1, // isXAxis !0 ); }, // ofCurrent noCentroid: -1 }, TouchHistoryMath_default = TouchHistoryMath; //# sourceMappingURL=index.js.map