@tamagui/react-native-use-responder-events
Advanced tools
Comparing version 1.125.6 to 1.125.7
@@ -1,4 +0,5 @@ | ||
import { getBoundingClientRect } from "./utils"; | ||
var emptyFunction = function() { | ||
}, emptyObject = {}, emptyArray = []; | ||
import { getBoundingClientRect } from "./utils.native.js"; | ||
var emptyFunction = function () {}, | ||
emptyObject = {}, | ||
emptyArray = []; | ||
function normalizeIdentifier(identifier) { | ||
@@ -8,5 +9,20 @@ return identifier > 20 ? identifier % 20 : identifier; | ||
function createResponderEvent(domEvent, responderTouchHistoryStore) { | ||
var rect, propagationWasStopped = !1, changedTouches, touches, domEventChangedTouches = domEvent.changedTouches, domEventType = domEvent.type, metaKey = domEvent.metaKey === !0, shiftKey = domEvent.shiftKey === !0, force = domEventChangedTouches?.[0].force || 0, identifier = normalizeIdentifier(domEventChangedTouches?.[0].identifier || 0), clientX = domEventChangedTouches?.[0].clientX || domEvent.clientX, clientY = domEventChangedTouches?.[0].clientY || domEvent.clientY, pageX = domEventChangedTouches?.[0].pageX || domEvent.pageX, pageY = domEventChangedTouches?.[0].pageY || domEvent.pageY, preventDefault = typeof domEvent.preventDefault == "function" ? domEvent.preventDefault.bind(domEvent) : emptyFunction, timestamp = domEvent.timeStamp; | ||
var rect, | ||
propagationWasStopped = !1, | ||
changedTouches, | ||
touches, | ||
domEventChangedTouches = domEvent.changedTouches, | ||
domEventType = domEvent.type, | ||
metaKey = domEvent.metaKey === !0, | ||
shiftKey = domEvent.shiftKey === !0, | ||
force = domEventChangedTouches?.[0].force || 0, | ||
identifier = normalizeIdentifier(domEventChangedTouches?.[0].identifier || 0), | ||
clientX = domEventChangedTouches?.[0].clientX || domEvent.clientX, | ||
clientY = domEventChangedTouches?.[0].clientY || domEvent.clientY, | ||
pageX = domEventChangedTouches?.[0].pageX || domEvent.pageX, | ||
pageY = domEventChangedTouches?.[0].pageY || domEvent.pageY, | ||
preventDefault = typeof domEvent.preventDefault == "function" ? domEvent.preventDefault.bind(domEvent) : emptyFunction, | ||
timestamp = domEvent.timeStamp; | ||
function normalizeTouches(touches2) { | ||
return Array.prototype.slice.call(touches2).map(function(touch) { | ||
return Array.prototype.slice.call(touches2).map(function (touch) { | ||
return { | ||
@@ -28,21 +44,17 @@ force: touch.force, | ||
} | ||
if (domEventChangedTouches != null) | ||
changedTouches = normalizeTouches(domEventChangedTouches), touches = normalizeTouches(domEvent.touches); | ||
else { | ||
var emulatedTouches = [ | ||
{ | ||
force, | ||
identifier, | ||
get locationX() { | ||
return locationX(clientX); | ||
}, | ||
get locationY() { | ||
return locationY(clientY); | ||
}, | ||
pageX, | ||
pageY, | ||
target: domEvent.target, | ||
timestamp | ||
} | ||
]; | ||
if (domEventChangedTouches != null) changedTouches = normalizeTouches(domEventChangedTouches), touches = normalizeTouches(domEvent.touches);else { | ||
var emulatedTouches = [{ | ||
force, | ||
identifier, | ||
get locationX() { | ||
return locationX(clientX); | ||
}, | ||
get locationY() { | ||
return locationY(clientY); | ||
}, | ||
pageX, | ||
pageY, | ||
target: domEvent.target, | ||
timestamp | ||
}]; | ||
changedTouches = emulatedTouches, touches = domEventType === "mouseup" || domEventType === "dragstart" ? emptyArray : emulatedTouches; | ||
@@ -96,14 +108,10 @@ } | ||
function locationX(x) { | ||
if (rect = rect || getBoundingClientRect(responderEvent.currentTarget), rect) | ||
return x - rect.left; | ||
if (rect = rect || getBoundingClientRect(responderEvent.currentTarget), rect) return x - rect.left; | ||
} | ||
function locationY(y) { | ||
if (rect = rect || getBoundingClientRect(responderEvent.currentTarget), rect) | ||
return y - rect.top; | ||
if (rect = rect || getBoundingClientRect(responderEvent.currentTarget), rect) return y - rect.top; | ||
} | ||
return responderEvent; | ||
} | ||
export { | ||
createResponderEvent as default | ||
}; | ||
//# sourceMappingURL=createResponderEvent.js.map | ||
export { createResponderEvent as default }; | ||
//# sourceMappingURL=createResponderEvent.native.js.map |
@@ -1,2 +0,2 @@ | ||
export * from "./useResponderEvents"; | ||
//# sourceMappingURL=index.js.map | ||
export * from "./useResponderEvents.native.js"; | ||
//# sourceMappingURL=index.native.js.map |
@@ -1,39 +0,37 @@ | ||
import createResponderEvent from "./createResponderEvent"; | ||
import { ResponderTouchHistoryStore } from "./ResponderTouchHistoryStore"; | ||
import { isCancelish, isEndish, isMoveish, isScroll, isSelectionChange, isStartish } from "./types"; | ||
import { canUseDOM } from "./utils"; | ||
import { getLowestCommonAncestor, getResponderPaths, hasTargetTouches, hasValidSelection, isPrimaryPointerDown, setResponderId } from "./utils"; | ||
var emptyObject = {}, startRegistration = [ | ||
"onStartShouldSetResponderCapture", | ||
"onStartShouldSetResponder", | ||
{ | ||
import createResponderEvent from "./createResponderEvent.native.js"; | ||
import { ResponderTouchHistoryStore } from "./ResponderTouchHistoryStore.native.js"; | ||
import { isCancelish, isEndish, isMoveish, isScroll, isSelectionChange, isStartish } from "./types.native.js"; | ||
import { canUseDOM } from "./utils.native.js"; | ||
import { getLowestCommonAncestor, getResponderPaths, hasTargetTouches, hasValidSelection, isPrimaryPointerDown, setResponderId } from "./utils.native.js"; | ||
var emptyObject = {}, | ||
startRegistration = ["onStartShouldSetResponderCapture", "onStartShouldSetResponder", { | ||
bubbles: !0 | ||
} | ||
], moveRegistration = [ | ||
"onMoveShouldSetResponderCapture", | ||
"onMoveShouldSetResponder", | ||
{ | ||
}], | ||
moveRegistration = ["onMoveShouldSetResponderCapture", "onMoveShouldSetResponder", { | ||
bubbles: !0 | ||
} | ||
], scrollRegistration = [ | ||
"onScrollShouldSetResponderCapture", | ||
"onScrollShouldSetResponder", | ||
{ | ||
}], | ||
scrollRegistration = ["onScrollShouldSetResponderCapture", "onScrollShouldSetResponder", { | ||
bubbles: !1 | ||
} | ||
], shouldSetResponderEvents = { | ||
touchstart: startRegistration, | ||
mousedown: startRegistration, | ||
touchmove: moveRegistration, | ||
mousemove: moveRegistration, | ||
scroll: scrollRegistration | ||
}, emptyResponder = { | ||
id: null, | ||
idPath: null, | ||
node: null | ||
}, responderListenersMap = /* @__PURE__ */ new Map(), isEmulatingMouseEvents = !1, trackedTouchCount = 0, currentResponder = { | ||
id: null, | ||
node: null, | ||
idPath: null | ||
}, responderTouchHistoryStore = new ResponderTouchHistoryStore(); | ||
}], | ||
shouldSetResponderEvents = { | ||
touchstart: startRegistration, | ||
mousedown: startRegistration, | ||
touchmove: moveRegistration, | ||
mousemove: moveRegistration, | ||
scroll: scrollRegistration | ||
}, | ||
emptyResponder = { | ||
id: null, | ||
idPath: null, | ||
node: null | ||
}, | ||
responderListenersMap = /* @__PURE__ */new Map(), | ||
isEmulatingMouseEvents = !1, | ||
trackedTouchCount = 0, | ||
currentResponder = { | ||
id: null, | ||
node: null, | ||
idPath: null | ||
}, | ||
responderTouchHistoryStore = new ResponderTouchHistoryStore(); | ||
function changeCurrentResponder(responder) { | ||
@@ -47,5 +45,8 @@ currentResponder = responder; | ||
function eventListener(domEvent) { | ||
var eventType = domEvent.type, eventTarget = domEvent.target; | ||
if (eventType === "touchstart" && (isEmulatingMouseEvents = !0), (eventType === "touchmove" || trackedTouchCount > 1) && (isEmulatingMouseEvents = !1), // Ignore browser emulated mouse events | ||
!(eventType === "mousedown" && isEmulatingMouseEvents || eventType === "mousemove" && isEmulatingMouseEvents || // Ignore mousemove if a mousedown didn't occur first | ||
var eventType = domEvent.type, | ||
eventTarget = domEvent.target; | ||
if (eventType === "touchstart" && (isEmulatingMouseEvents = !0), (eventType === "touchmove" || trackedTouchCount > 1) && (isEmulatingMouseEvents = !1), | ||
// Ignore browser emulated mouse events | ||
!(eventType === "mousedown" && isEmulatingMouseEvents || eventType === "mousemove" && isEmulatingMouseEvents || | ||
// Ignore mousemove if a mousedown didn't occur first | ||
eventType === "mousemove" && trackedTouchCount < 1)) { | ||
@@ -56,11 +57,20 @@ if (isEmulatingMouseEvents && eventType === "mouseup") { | ||
} | ||
var isStartEvent = isStartish(eventType) && isPrimaryPointerDown(domEvent), isMoveEvent = isMoveish(eventType), isEndEvent = isEndish(eventType), isScrollEvent = isScroll(eventType), isSelectionChangeEvent = isSelectionChange(eventType), responderEvent = createResponderEvent(domEvent, responderTouchHistoryStore); | ||
var isStartEvent = isStartish(eventType) && isPrimaryPointerDown(domEvent), | ||
isMoveEvent = isMoveish(eventType), | ||
isEndEvent = isEndish(eventType), | ||
isScrollEvent = isScroll(eventType), | ||
isSelectionChangeEvent = isSelectionChange(eventType), | ||
responderEvent = createResponderEvent(domEvent, responderTouchHistoryStore); | ||
(isStartEvent || isMoveEvent || isEndEvent) && (domEvent.touches ? trackedTouchCount = domEvent.touches.length : isStartEvent ? trackedTouchCount = 1 : isEndEvent && (trackedTouchCount = 0), responderTouchHistoryStore.recordTouchTrack(eventType, responderEvent.nativeEvent)); | ||
var eventPaths = getResponderPaths(domEvent), wasNegotiated = !1, wantsResponder; | ||
var eventPaths = getResponderPaths(domEvent), | ||
wasNegotiated = !1, | ||
wantsResponder; | ||
if (isStartEvent || isMoveEvent || isScrollEvent && trackedTouchCount > 0) { | ||
var currentResponderIdPath = currentResponder.idPath, eventIdPath = eventPaths.idPath; | ||
var currentResponderIdPath = currentResponder.idPath, | ||
eventIdPath = eventPaths.idPath; | ||
if (currentResponderIdPath != null && eventIdPath != null) { | ||
var lowestCommonAncestor = getLowestCommonAncestor(currentResponderIdPath, eventIdPath); | ||
if (lowestCommonAncestor != null) { | ||
var indexOfLowestCommonAncestor = eventIdPath.indexOf(lowestCommonAncestor), index = indexOfLowestCommonAncestor + (lowestCommonAncestor === currentResponder.id ? 1 : 0); | ||
var indexOfLowestCommonAncestor = eventIdPath.indexOf(lowestCommonAncestor), | ||
index = indexOfLowestCommonAncestor + (lowestCommonAncestor === currentResponder.id ? 1 : 0); | ||
eventPaths = { | ||
@@ -70,4 +80,3 @@ idPath: eventIdPath.slice(index), | ||
}; | ||
} else | ||
eventPaths = null; | ||
} else eventPaths = null; | ||
} | ||
@@ -77,15 +86,29 @@ eventPaths != null && (wantsResponder = findWantsResponder(eventPaths, domEvent, responderEvent), wantsResponder != null && (attemptTransfer(responderEvent, wantsResponder), wasNegotiated = !0)); | ||
if (currentResponder.id != null && currentResponder.node != null) { | ||
var { id, node } = currentResponder, { onResponderStart, onResponderMove, onResponderEnd, onResponderRelease, onResponderTerminate, onResponderTerminationRequest } = getResponderConfig(id); | ||
if (responderEvent.bubbles = !1, responderEvent.cancelable = !1, responderEvent.currentTarget = node, isStartEvent) | ||
onResponderStart != null && (responderEvent.dispatchConfig.registrationName = "onResponderStart", onResponderStart(responderEvent)); | ||
else if (isMoveEvent) | ||
onResponderMove != null && (responderEvent.dispatchConfig.registrationName = "onResponderMove", onResponderMove(responderEvent)); | ||
else { | ||
var isTerminateEvent = isCancelish(eventType) || // native context menu | ||
eventType === "contextmenu" || // window blur | ||
eventType === "blur" && eventTarget === window || // responder (or ancestors) blur | ||
eventType === "blur" && eventTarget.contains(node) && domEvent.relatedTarget !== node || // native scroll without using a pointer | ||
isScrollEvent && trackedTouchCount === 0 || // native scroll on node that is parent of the responder (allow siblings to scroll) | ||
isScrollEvent && eventTarget.contains(node) && eventTarget !== node || // native select/selectionchange on node | ||
isSelectionChangeEvent && hasValidSelection(domEvent), isReleaseEvent = isEndEvent && !isTerminateEvent && !hasTargetTouches(node, domEvent.touches); | ||
var { | ||
id, | ||
node | ||
} = currentResponder, | ||
{ | ||
onResponderStart, | ||
onResponderMove, | ||
onResponderEnd, | ||
onResponderRelease, | ||
onResponderTerminate, | ||
onResponderTerminationRequest | ||
} = getResponderConfig(id); | ||
if (responderEvent.bubbles = !1, responderEvent.cancelable = !1, responderEvent.currentTarget = node, isStartEvent) onResponderStart != null && (responderEvent.dispatchConfig.registrationName = "onResponderStart", onResponderStart(responderEvent));else if (isMoveEvent) onResponderMove != null && (responderEvent.dispatchConfig.registrationName = "onResponderMove", onResponderMove(responderEvent));else { | ||
var isTerminateEvent = isCancelish(eventType) || | ||
// native context menu | ||
eventType === "contextmenu" || | ||
// window blur | ||
eventType === "blur" && eventTarget === window || | ||
// responder (or ancestors) blur | ||
eventType === "blur" && eventTarget.contains(node) && domEvent.relatedTarget !== node || | ||
// native scroll without using a pointer | ||
isScrollEvent && trackedTouchCount === 0 || | ||
// native scroll on node that is parent of the responder (allow siblings to scroll) | ||
isScrollEvent && eventTarget.contains(node) && eventTarget !== node || | ||
// native select/selectionchange on node | ||
isSelectionChangeEvent && hasValidSelection(domEvent), | ||
isReleaseEvent = isEndEvent && !isTerminateEvent && !hasTargetTouches(node, domEvent.touches); | ||
if (isEndEvent && onResponderEnd != null && (responderEvent.dispatchConfig.registrationName = "onResponderEnd", onResponderEnd(responderEvent)), isReleaseEvent && (onResponderRelease != null && (responderEvent.dispatchConfig.registrationName = "onResponderRelease", onResponderRelease(responderEvent)), changeCurrentResponder(emptyResponder)), isTerminateEvent) { | ||
@@ -102,31 +125,36 @@ var shouldTerminate = !0; | ||
if (shouldSetCallbacks != null) { | ||
for (var { idPath, nodePath } = eventPaths, shouldSetCallbackCaptureName = shouldSetCallbacks[0], shouldSetCallbackBubbleName = shouldSetCallbacks[1], { bubbles } = shouldSetCallbacks[2], check = function(id3, node3, callbackName) { | ||
var config = getResponderConfig(id3), shouldSetCallback = config[callbackName]; | ||
if (shouldSetCallback != null && (responderEvent.currentTarget = node3, shouldSetCallback(responderEvent) === !0)) { | ||
var prunedIdPath = idPath.slice(idPath.indexOf(id3)); | ||
return { | ||
id: id3, | ||
node: node3, | ||
idPath: prunedIdPath | ||
}; | ||
} | ||
}, i = idPath.length - 1; i >= 0; i--) { | ||
var id = idPath[i], node = nodePath[i], result = check(id, node, shouldSetCallbackCaptureName); | ||
if (result != null) | ||
return result; | ||
if (responderEvent.isPropagationStopped() === !0) | ||
return; | ||
for (var { | ||
idPath, | ||
nodePath | ||
} = eventPaths, shouldSetCallbackCaptureName = shouldSetCallbacks[0], shouldSetCallbackBubbleName = shouldSetCallbacks[1], { | ||
bubbles | ||
} = shouldSetCallbacks[2], check = function (id3, node3, callbackName) { | ||
var config = getResponderConfig(id3), | ||
shouldSetCallback = config[callbackName]; | ||
if (shouldSetCallback != null && (responderEvent.currentTarget = node3, shouldSetCallback(responderEvent) === !0)) { | ||
var prunedIdPath = idPath.slice(idPath.indexOf(id3)); | ||
return { | ||
id: id3, | ||
node: node3, | ||
idPath: prunedIdPath | ||
}; | ||
} | ||
}, i = idPath.length - 1; i >= 0; i--) { | ||
var id = idPath[i], | ||
node = nodePath[i], | ||
result = check(id, node, shouldSetCallbackCaptureName); | ||
if (result != null) return result; | ||
if (responderEvent.isPropagationStopped() === !0) return; | ||
} | ||
if (bubbles) | ||
for (var i1 = 0; i1 < idPath.length; i1++) { | ||
var id1 = idPath[i1], node1 = nodePath[i1], result1 = check(id1, node1, shouldSetCallbackBubbleName); | ||
if (result1 != null) | ||
return result1; | ||
if (responderEvent.isPropagationStopped() === !0) | ||
return; | ||
} | ||
else { | ||
var id2 = idPath[0], node2 = nodePath[0], target = domEvent.target; | ||
if (target === node2) | ||
return check(id2, node2, shouldSetCallbackBubbleName); | ||
if (bubbles) for (var i1 = 0; i1 < idPath.length; i1++) { | ||
var id1 = idPath[i1], | ||
node1 = nodePath[i1], | ||
result1 = check(id1, node1, shouldSetCallbackBubbleName); | ||
if (result1 != null) return result1; | ||
if (responderEvent.isPropagationStopped() === !0) return; | ||
} else { | ||
var id2 = idPath[0], | ||
node2 = nodePath[0], | ||
target = domEvent.target; | ||
if (target === node2) return check(id2, node2, shouldSetCallbackBubbleName); | ||
} | ||
@@ -136,33 +164,36 @@ } | ||
function attemptTransfer(responderEvent, wantsResponder) { | ||
var { id: currentId, node: currentNode } = currentResponder, { id, node } = wantsResponder, { onResponderGrant, onResponderReject } = getResponderConfig(id); | ||
if (responderEvent.bubbles = !1, responderEvent.cancelable = !1, responderEvent.currentTarget = node, currentId == null) | ||
onResponderGrant != null && (responderEvent.currentTarget = node, responderEvent.dispatchConfig.registrationName = "onResponderGrant", onResponderGrant(responderEvent)), changeCurrentResponder(wantsResponder); | ||
else { | ||
var { onResponderTerminate, onResponderTerminationRequest } = getResponderConfig(currentId), allowTransfer = !0; | ||
var { | ||
id: currentId, | ||
node: currentNode | ||
} = currentResponder, | ||
{ | ||
id, | ||
node | ||
} = wantsResponder, | ||
{ | ||
onResponderGrant, | ||
onResponderReject | ||
} = getResponderConfig(id); | ||
if (responderEvent.bubbles = !1, responderEvent.cancelable = !1, responderEvent.currentTarget = node, currentId == null) onResponderGrant != null && (responderEvent.currentTarget = node, responderEvent.dispatchConfig.registrationName = "onResponderGrant", onResponderGrant(responderEvent)), changeCurrentResponder(wantsResponder);else { | ||
var { | ||
onResponderTerminate, | ||
onResponderTerminationRequest | ||
} = getResponderConfig(currentId), | ||
allowTransfer = !0; | ||
onResponderTerminationRequest != null && (responderEvent.currentTarget = currentNode, responderEvent.dispatchConfig.registrationName = "onResponderTerminationRequest", onResponderTerminationRequest(responderEvent) === !1 && (allowTransfer = !1)), allowTransfer ? (onResponderTerminate != null && (responderEvent.currentTarget = currentNode, responderEvent.dispatchConfig.registrationName = "onResponderTerminate", onResponderTerminate(responderEvent)), onResponderGrant != null && (responderEvent.currentTarget = node, responderEvent.dispatchConfig.registrationName = "onResponderGrant", onResponderGrant(responderEvent)), changeCurrentResponder(wantsResponder)) : onResponderReject != null && (responderEvent.currentTarget = node, responderEvent.dispatchConfig.registrationName = "onResponderReject", onResponderReject(responderEvent)); | ||
} | ||
} | ||
var documentEventsCapturePhase = [ | ||
"blur", | ||
"scroll" | ||
], documentEventsBubblePhase = [ | ||
var documentEventsCapturePhase = ["blur", "scroll"], | ||
documentEventsBubblePhase = [ | ||
// mouse | ||
"mousedown", | ||
"mousemove", | ||
"mouseup", | ||
"dragstart", | ||
"mousedown", "mousemove", "mouseup", "dragstart", | ||
// touch | ||
"touchstart", | ||
"touchmove", | ||
"touchend", | ||
"touchcancel", | ||
"touchstart", "touchmove", "touchend", "touchcancel", | ||
// other | ||
"contextmenu", | ||
"select", | ||
"selectionchange" | ||
], isTamaguiResponderActive = Symbol(); | ||
"contextmenu", "select", "selectionchange"], | ||
isTamaguiResponderActive = Symbol(); | ||
function attachListeners() { | ||
canUseDOM && !window[isTamaguiResponderActive] && (window.addEventListener("blur", eventListener), documentEventsBubblePhase.forEach(function(eventType) { | ||
canUseDOM && !window[isTamaguiResponderActive] && (window.addEventListener("blur", eventListener), documentEventsBubblePhase.forEach(function (eventType) { | ||
document.addEventListener(eventType, eventListener); | ||
}), documentEventsCapturePhase.forEach(function(eventType) { | ||
}), documentEventsCapturePhase.forEach(function (eventType) { | ||
document.addEventListener(eventType, eventListener, !0); | ||
@@ -178,5 +209,10 @@ }), window[isTamaguiResponderActive] = !0); | ||
function terminateResponder() { | ||
var { id, node } = currentResponder; | ||
var { | ||
id, | ||
node | ||
} = currentResponder; | ||
if (id != null && node != null) { | ||
var { onResponderTerminate } = getResponderConfig(id); | ||
var { | ||
onResponderTerminate | ||
} = getResponderConfig(id); | ||
if (onResponderTerminate != null) { | ||
@@ -193,9 +229,3 @@ var event = createResponderEvent({}, responderTouchHistoryStore); | ||
} | ||
export { | ||
addNode, | ||
attachListeners, | ||
getResponderNode, | ||
removeNode, | ||
terminateResponder | ||
}; | ||
//# sourceMappingURL=ResponderSystem.js.map | ||
export { addNode, attachListeners, getResponderNode, removeNode, terminateResponder }; | ||
//# sourceMappingURL=ResponderSystem.native.js.map |
@@ -1,5 +0,4 @@ | ||
import { isEndish, isMoveish, isStartish } from "./types"; | ||
import { isEndish, isMoveish, isStartish } from "./types.native.js"; | ||
function _class_call_check(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) | ||
throw new TypeError("Cannot call a class as a function"); | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
@@ -23,33 +22,31 @@ function _defineProperties(target, props) { | ||
} | ||
var ResponderTouchHistoryStore = /* @__PURE__ */ function() { | ||
"use strict"; | ||
function ResponderTouchHistoryStore2() { | ||
_class_call_check(this, ResponderTouchHistoryStore2), _define_property(this, "_touchHistory", { | ||
touchBank: [], | ||
//Array<TouchRecord> | ||
numberActiveTouches: 0, | ||
// If there is only one active touch, we remember its location. This prevents | ||
// us having to loop through all of the touches all the time in the most | ||
// common case. | ||
indexOfSingleActiveTouch: -1, | ||
mostRecentTimeStamp: 0 | ||
}); | ||
} | ||
return _create_class(ResponderTouchHistoryStore2, [ | ||
{ | ||
var ResponderTouchHistoryStore = /* @__PURE__ */function () { | ||
"use strict"; | ||
function ResponderTouchHistoryStore2() { | ||
_class_call_check(this, ResponderTouchHistoryStore2), _define_property(this, "_touchHistory", { | ||
touchBank: [], | ||
//Array<TouchRecord> | ||
numberActiveTouches: 0, | ||
// If there is only one active touch, we remember its location. This prevents | ||
// us having to loop through all of the touches all the time in the most | ||
// common case. | ||
indexOfSingleActiveTouch: -1, | ||
mostRecentTimeStamp: 0 | ||
}); | ||
} | ||
return _create_class(ResponderTouchHistoryStore2, [{ | ||
key: "recordTouchTrack", | ||
value: function(topLevelType, nativeEvent) { | ||
value: function (topLevelType, nativeEvent) { | ||
var touchHistory = this._touchHistory; | ||
if (isMoveish(topLevelType)) | ||
nativeEvent.changedTouches.forEach(function(touch) { | ||
return recordTouchMove(touch, touchHistory); | ||
}); | ||
else if (isStartish(topLevelType)) | ||
nativeEvent.changedTouches.forEach(function(touch) { | ||
return recordTouchStart(touch, touchHistory); | ||
}), touchHistory.numberActiveTouches = nativeEvent.touches.length, touchHistory.numberActiveTouches === 1 && (touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier); | ||
else if (isEndish(topLevelType) && (nativeEvent.changedTouches.forEach(function(touch) { | ||
if (isMoveish(topLevelType)) nativeEvent.changedTouches.forEach(function (touch) { | ||
return recordTouchMove(touch, touchHistory); | ||
});else if (isStartish(topLevelType)) nativeEvent.changedTouches.forEach(function (touch) { | ||
return recordTouchStart(touch, touchHistory); | ||
}), touchHistory.numberActiveTouches = nativeEvent.touches.length, touchHistory.numberActiveTouches === 1 && (touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier);else if (isEndish(topLevelType) && (nativeEvent.changedTouches.forEach(function (touch) { | ||
return recordTouchEnd(touch, touchHistory); | ||
}), touchHistory.numberActiveTouches = nativeEvent.touches.length, touchHistory.numberActiveTouches === 1)) { | ||
for (var { touchBank } = touchHistory, i = 0; i < touchBank.length; i++) { | ||
for (var { | ||
touchBank | ||
} = touchHistory, i = 0; i < touchBank.length; i++) { | ||
var touchTrackToCheck = touchBank[i]; | ||
@@ -67,11 +64,10 @@ if (touchTrackToCheck?.touchActive) { | ||
} | ||
}, | ||
{ | ||
}, { | ||
key: "touchHistory", | ||
get: function() { | ||
get: function () { | ||
return this._touchHistory; | ||
} | ||
} | ||
]), ResponderTouchHistoryStore2; | ||
}(), MAX_TOUCH_BANK = 20; | ||
}]), ResponderTouchHistoryStore2; | ||
}(), | ||
MAX_TOUCH_BANK = 20; | ||
function timestampForTouch(touch) { | ||
@@ -98,7 +94,10 @@ return touch.timeStamp || touch.timestamp; | ||
function getTouchIdentifier(param) { | ||
var { identifier } = param; | ||
var { | ||
identifier | ||
} = param; | ||
return identifier == null && console.error("Touch object is missing identifier."), process.env.NODE_ENV === "development" && identifier > MAX_TOUCH_BANK && console.error("Touch identifier %s is greater than maximum supported %s which causes performance issues backfilling array locations for all of the indices.", identifier, MAX_TOUCH_BANK), identifier; | ||
} | ||
function recordTouchStart(touch, touchHistory) { | ||
var identifier = getTouchIdentifier(touch), touchRecord = touchHistory.touchBank[identifier]; | ||
var identifier = getTouchIdentifier(touch), | ||
touchRecord = touchHistory.touchBank[identifier]; | ||
touchRecord ? resetTouchRecord(touchRecord, touch) : touchHistory.touchBank[identifier] = createTouchRecord(touch), touchHistory.mostRecentTimeStamp = timestampForTouch(touch); | ||
@@ -127,8 +126,9 @@ } | ||
function printTouchBank(touchHistory) { | ||
var { touchBank } = touchHistory, printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK)); | ||
var { | ||
touchBank | ||
} = touchHistory, | ||
printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK)); | ||
return touchBank.length > MAX_TOUCH_BANK && (printed += ` (original size: ${touchBank.length})`), printed; | ||
} | ||
export { | ||
ResponderTouchHistoryStore | ||
}; | ||
//# sourceMappingURL=ResponderTouchHistoryStore.js.map | ||
export { ResponderTouchHistoryStore }; | ||
//# sourceMappingURL=ResponderTouchHistoryStore.native.js.map |
@@ -1,2 +0,15 @@ | ||
var BLUR = "blur", CONTEXT_MENU = "contextmenu", FOCUS_OUT = "focusout", MOUSE_DOWN = "mousedown", MOUSE_MOVE = "mousemove", MOUSE_UP = "mouseup", MOUSE_CANCEL = "dragstart", TOUCH_START = "touchstart", TOUCH_MOVE = "touchmove", TOUCH_END = "touchend", TOUCH_CANCEL = "touchcancel", SCROLL = "scroll", SELECT = "select", SELECTION_CHANGE = "selectionchange"; | ||
var BLUR = "blur", | ||
CONTEXT_MENU = "contextmenu", | ||
FOCUS_OUT = "focusout", | ||
MOUSE_DOWN = "mousedown", | ||
MOUSE_MOVE = "mousemove", | ||
MOUSE_UP = "mouseup", | ||
MOUSE_CANCEL = "dragstart", | ||
TOUCH_START = "touchstart", | ||
TOUCH_MOVE = "touchmove", | ||
TOUCH_END = "touchend", | ||
TOUCH_CANCEL = "touchcancel", | ||
SCROLL = "scroll", | ||
SELECT = "select", | ||
SELECTION_CHANGE = "selectionchange"; | ||
function isStartish(eventType) { | ||
@@ -20,24 +33,3 @@ return eventType === TOUCH_START || eventType === MOUSE_DOWN; | ||
} | ||
export { | ||
BLUR, | ||
CONTEXT_MENU, | ||
FOCUS_OUT, | ||
MOUSE_CANCEL, | ||
MOUSE_DOWN, | ||
MOUSE_MOVE, | ||
MOUSE_UP, | ||
SCROLL, | ||
SELECT, | ||
SELECTION_CHANGE, | ||
TOUCH_CANCEL, | ||
TOUCH_END, | ||
TOUCH_MOVE, | ||
TOUCH_START, | ||
isCancelish, | ||
isEndish, | ||
isMoveish, | ||
isScroll, | ||
isSelectionChange, | ||
isStartish | ||
}; | ||
//# sourceMappingURL=types.js.map | ||
export { BLUR, CONTEXT_MENU, FOCUS_OUT, MOUSE_CANCEL, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, SCROLL, SELECT, SELECTION_CHANGE, TOUCH_CANCEL, TOUCH_END, TOUCH_MOVE, TOUCH_START, isCancelish, isEndish, isMoveish, isScroll, isSelectionChange, isStartish }; | ||
//# sourceMappingURL=types.native.js.map |
import * as React from "react"; | ||
import * as ResponderSystem from "./ResponderSystem"; | ||
export * from "./utils"; | ||
var emptyObject = {}, Attached = /* @__PURE__ */ new WeakMap(), Ids = /* @__PURE__ */ new WeakMap(); | ||
import * as ResponderSystem from "./ResponderSystem.native.js"; | ||
export * from "./utils.native.js"; | ||
var emptyObject = {}, | ||
Attached = /* @__PURE__ */new WeakMap(), | ||
Ids = /* @__PURE__ */new WeakMap(); | ||
function useResponderEvents(hostRef) { | ||
var configIn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : emptyObject, _hostRef_current, config = getResponderConfigIfDefined(configIn), node = (hostRef == null || (_hostRef_current = hostRef.current) === null || _hostRef_current === void 0 ? void 0 : _hostRef_current.host) || hostRef?.current; | ||
React.useEffect(function() { | ||
var configIn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : emptyObject, | ||
_hostRef_current, | ||
config = getResponderConfigIfDefined(configIn), | ||
node = (hostRef == null || (_hostRef_current = hostRef.current) === null || _hostRef_current === void 0 ? void 0 : _hostRef_current.host) || hostRef?.current; | ||
React.useEffect(function () { | ||
if (config !== emptyObject) { | ||
ResponderSystem.attachListeners(), Ids.has(hostRef) || Ids.set(hostRef, `${Math.random()}`); | ||
var id = Ids.get(hostRef); | ||
return ResponderSystem.addNode(id, node, config), Attached.set(hostRef, !0), function() { | ||
return ResponderSystem.addNode(id, node, config), Attached.set(hostRef, !0), function () { | ||
ResponderSystem.removeNode(node), Attached.set(hostRef, !1); | ||
}; | ||
} | ||
}, [ | ||
config, | ||
hostRef | ||
]), process.env.NODE_ENV === "development" && (React.useDebugValue({ | ||
}, [config, hostRef]), process.env.NODE_ENV === "development" && (React.useDebugValue({ | ||
isResponder: node === ResponderSystem.getResponderNode() | ||
@@ -23,3 +25,20 @@ }), React.useDebugValue(config)); | ||
function getResponderConfigIfDefined(param) { | ||
var { onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderEnd, onResponderGrant, onResponderMove, onResponderReject, onResponderRelease, onResponderStart, onResponderTerminate, onResponderTerminationRequest, onScrollShouldSetResponder, onScrollShouldSetResponderCapture, onSelectionChangeShouldSetResponder, onSelectionChangeShouldSetResponderCapture, onStartShouldSetResponder, onStartShouldSetResponderCapture } = param; | ||
var { | ||
onMoveShouldSetResponder, | ||
onMoveShouldSetResponderCapture, | ||
onResponderEnd, | ||
onResponderGrant, | ||
onResponderMove, | ||
onResponderReject, | ||
onResponderRelease, | ||
onResponderStart, | ||
onResponderTerminate, | ||
onResponderTerminationRequest, | ||
onScrollShouldSetResponder, | ||
onScrollShouldSetResponderCapture, | ||
onSelectionChangeShouldSetResponder, | ||
onSelectionChangeShouldSetResponderCapture, | ||
onStartShouldSetResponder, | ||
onStartShouldSetResponderCapture | ||
} = param; | ||
return onMoveShouldSetResponder || onMoveShouldSetResponderCapture || onResponderEnd || onResponderGrant || onResponderMove || onResponderReject || onResponderRelease || onResponderStart || onResponderTerminate || onResponderTerminationRequest || onScrollShouldSetResponder || onScrollShouldSetResponderCapture || onSelectionChangeShouldSetResponder || onSelectionChangeShouldSetResponderCapture || onStartShouldSetResponder || onStartShouldSetResponderCapture ? { | ||
@@ -44,6 +63,3 @@ onMoveShouldSetResponder, | ||
} | ||
export { | ||
getResponderConfigIfDefined, | ||
useResponderEvents | ||
}; | ||
//# sourceMappingURL=useResponderEvents.js.map | ||
export { getResponderConfigIfDefined, useResponderEvents }; | ||
//# sourceMappingURL=useResponderEvents.native.js.map |
@@ -1,8 +0,10 @@ | ||
var keyName = "__reactResponderId", canUseDOM = !!(typeof window < "u" && window.document && window.document.createElement), getBoundingClientRect = function(node) { | ||
if (node && node.nodeType === 1 && node.getBoundingClientRect) | ||
return node.getBoundingClientRect(); | ||
}; | ||
var keyName = "__reactResponderId", | ||
canUseDOM = !!(typeof window < "u" && window.document && window.document.createElement), | ||
getBoundingClientRect = function (node) { | ||
if (node && node.nodeType === 1 && node.getBoundingClientRect) return node.getBoundingClientRect(); | ||
}; | ||
function getEventPath(domEvent) { | ||
if (domEvent.type === "selectionchange") { | ||
var _window_getSelection, target = (_window_getSelection = window.getSelection()) === null || _window_getSelection === void 0 ? void 0 : _window_getSelection.anchorNode; | ||
var _window_getSelection, | ||
target = (_window_getSelection = window.getSelection()) === null || _window_getSelection === void 0 ? void 0 : _window_getSelection.anchorNode; | ||
return composedPathFallback(target); | ||
@@ -14,4 +16,3 @@ } | ||
function composedPathFallback(target) { | ||
for (var path = []; target != null && target !== document.body; ) | ||
path.push(target), target = target.parentNode; | ||
for (var path = []; target != null && target !== document.body;) path.push(target), target = target.parentNode; | ||
return path; | ||
@@ -27,3 +28,4 @@ } | ||
for (var idPath = [], nodePath = [], eventPath = getEventPath(domEvent), i = 0; i < eventPath.length; i++) { | ||
var node = eventPath[i], id = getResponderId(node); | ||
var node = eventPath[i], | ||
id = getResponderId(node); | ||
id != null && (idPath.push(id), nodePath.push(node)); | ||
@@ -37,15 +39,17 @@ } | ||
function getLowestCommonAncestor(pathA, pathB) { | ||
var pathALength = pathA.length, pathBLength = pathB.length; | ||
var pathALength = pathA.length, | ||
pathBLength = pathB.length; | ||
if ( | ||
// If either path is empty | ||
pathALength === 0 || pathBLength === 0 || // If the last elements aren't the same there can't be a common ancestor | ||
// that is connected to the responder system | ||
pathA[pathALength - 1] !== pathB[pathBLength - 1] | ||
) | ||
return null; | ||
var itemA = pathA[0], indexA = 0, itemB = pathB[0], indexB = 0; | ||
// If either path is empty | ||
pathALength === 0 || pathBLength === 0 || | ||
// If the last elements aren't the same there can't be a common ancestor | ||
// that is connected to the responder system | ||
pathA[pathALength - 1] !== pathB[pathBLength - 1]) return null; | ||
var itemA = pathA[0], | ||
indexA = 0, | ||
itemB = pathB[0], | ||
indexB = 0; | ||
pathALength - pathBLength > 0 && (indexA = pathALength - pathBLength, itemA = pathA[indexA], pathALength = pathBLength), pathBLength - pathALength > 0 && (indexB = pathBLength - pathALength, itemB = pathB[indexB], pathBLength = pathALength); | ||
for (var depth = pathALength; depth--; ) { | ||
if (itemA === itemB) | ||
return itemA; | ||
for (var depth = pathALength; depth--;) { | ||
if (itemA === itemB) return itemA; | ||
itemA = pathA[indexA++], itemB = pathB[indexB++]; | ||
@@ -56,8 +60,6 @@ } | ||
function hasTargetTouches(target, touches) { | ||
if (!touches || touches.length === 0) | ||
return !1; | ||
if (!touches || touches.length === 0) return !1; | ||
for (var i = 0; i < touches.length; i++) { | ||
var node = touches[i].target; | ||
if (node != null && target.contains(node)) | ||
return !0; | ||
if (node != null && target.contains(node)) return !0; | ||
} | ||
@@ -70,3 +72,13 @@ return !1; | ||
function isPrimaryPointerDown(domEvent) { | ||
var { altKey, button, buttons, ctrlKey, type } = domEvent, isTouch = type === "touchstart" || type === "touchmove", isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1), isPrimaryMouseMove = type === "mousemove" && buttons === 1, noModifiers = altKey === !1 && ctrlKey === !1; | ||
var { | ||
altKey, | ||
button, | ||
buttons, | ||
ctrlKey, | ||
type | ||
} = domEvent, | ||
isTouch = type === "touchstart" || type === "touchmove", | ||
isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1), | ||
isPrimaryMouseMove = type === "mousemove" && buttons === 1, | ||
noModifiers = altKey === !1 && ctrlKey === !1; | ||
return !!(isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers); | ||
@@ -77,17 +89,10 @@ } | ||
if (!selection) return !1; | ||
var string = selection.toString(), anchorNode = selection.anchorNode, focusNode = selection.focusNode, isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE; | ||
var string = selection.toString(), | ||
anchorNode = selection.anchorNode, | ||
focusNode = selection.focusNode, | ||
isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE; | ||
return string.length >= 1 && string !== ` | ||
` && !!isTextNode; | ||
} | ||
export { | ||
canUseDOM, | ||
getBoundingClientRect, | ||
getLowestCommonAncestor, | ||
getResponderPaths, | ||
hasTargetTouches, | ||
hasValidSelection, | ||
isPrimaryPointerDown, | ||
isSelectionValid, | ||
setResponderId | ||
}; | ||
//# sourceMappingURL=utils.js.map | ||
export { canUseDOM, getBoundingClientRect, getLowestCommonAncestor, getResponderPaths, hasTargetTouches, hasValidSelection, isPrimaryPointerDown, isSelectionValid, setResponderId }; | ||
//# sourceMappingURL=utils.native.js.map |
{ | ||
"name": "@tamagui/react-native-use-responder-events", | ||
"version": "1.125.6", | ||
"version": "1.125.7", | ||
"types": "./types/index.d.ts", | ||
@@ -33,3 +33,3 @@ "main": "dist/cjs", | ||
"devDependencies": { | ||
"@tamagui/build": "1.125.6", | ||
"@tamagui/build": "1.125.7", | ||
"react": "*" | ||
@@ -36,0 +36,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
360570
5710