@tamagui/react-native-use-pressable
Advanced tools
Comparing version 1.0.1-rc.5.1 to 1.0.1-rc.6
@@ -76,3 +76,4 @@ "use strict"; | ||
const isValidKeyPress = (event) => { | ||
const key = event.key, target = event.target; | ||
const key = event.key; | ||
const target = event.target; | ||
const role = target.getAttribute("role"); | ||
@@ -172,3 +173,4 @@ const isSpacebar = key === " " || key === "Spacebar"; | ||
const disabled = this._config.disabled; | ||
const key = event.key, target = event.target; | ||
const key = event.key; | ||
const target = event.target; | ||
if (!disabled && isValidKeyPress(event)) { | ||
@@ -210,3 +212,6 @@ if (this._touchState === NOT_RESPONDER) { | ||
onResponderTerminationRequest: (event) => { | ||
const _this$_config = this._config, cancelable = _this$_config.cancelable, disabled = _this$_config.disabled, onLongPress = _this$_config.onLongPress; | ||
const _this$_config = this._config; | ||
const cancelable = _this$_config.cancelable; | ||
const disabled = _this$_config.disabled; | ||
const onLongPress = _this$_config.onLongPress; | ||
if (!disabled && onLongPress != null && this._isPointerTouch && event.nativeEvent.type === "contextmenu") { | ||
@@ -221,3 +226,5 @@ return false; | ||
onClick: (event) => { | ||
const _this$_config2 = this._config, disabled = _this$_config2.disabled, onPress = _this$_config2.onPress; | ||
const _this$_config2 = this._config; | ||
const disabled = _this$_config2.disabled; | ||
const onPress = _this$_config2.onPress; | ||
if (!disabled) { | ||
@@ -237,3 +244,5 @@ event.stopPropagation(); | ||
onContextMenu: (event) => { | ||
const _this$_config3 = this._config, disabled = _this$_config3.disabled, onLongPress = _this$_config3.onLongPress; | ||
const _this$_config3 = this._config; | ||
const disabled = _this$_config3.disabled; | ||
const onLongPress = _this$_config3.onLongPress; | ||
if (!disabled) { | ||
@@ -263,3 +272,3 @@ if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) { | ||
console.error( | ||
"PressResponder: Invalid signal " + signal + " for state " + prevState + " on responder" | ||
`PressResponder: Invalid signal ${signal} for state ${prevState} on responder` | ||
); | ||
@@ -294,7 +303,9 @@ } else if (prevState !== nextState) { | ||
if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) { | ||
const _this$_config4 = this._config, _onLongPress = _this$_config4.onLongPress, onPress = _this$_config4.onPress; | ||
const _this$_config4 = this._config; | ||
const _onLongPress = _this$_config4.onLongPress; | ||
const onPress = _this$_config4.onPress; | ||
if (onPress != null) { | ||
const isPressCanceledByLongPress = _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START; | ||
if (!isPressCanceledByLongPress) { | ||
if (!isNextActive && !isPrevActive) { | ||
if (!(isNextActive || isPrevActive)) { | ||
this._activate(event); | ||
@@ -309,3 +320,5 @@ this._deactivate(event); | ||
_activate(event) { | ||
const _this$_config5 = this._config, onPressChange = _this$_config5.onPressChange, onPressStart = _this$_config5.onPressStart; | ||
const _this$_config5 = this._config; | ||
const onPressChange = _this$_config5.onPressChange; | ||
const onPressStart = _this$_config5.onPressStart; | ||
const touch = getTouchFromResponderEvent(event); | ||
@@ -324,3 +337,5 @@ this._touchActivatePosition = { | ||
_deactivate(event) { | ||
const _this$_config6 = this._config, onPressChange = _this$_config6.onPressChange, onPressEnd = _this$_config6.onPressEnd; | ||
const _this$_config6 = this._config; | ||
const onPressChange = _this$_config6.onPressChange; | ||
const onPressEnd = _this$_config6.onPressEnd; | ||
function end() { | ||
@@ -377,3 +392,5 @@ if (onPressEnd != null) { | ||
function getTouchFromResponderEvent(event) { | ||
const _event$nativeEvent = event.nativeEvent, changedTouches = _event$nativeEvent.changedTouches, touches = _event$nativeEvent.touches; | ||
const _event$nativeEvent = event.nativeEvent; | ||
const changedTouches = _event$nativeEvent.changedTouches; | ||
const touches = _event$nativeEvent.touches; | ||
if (touches != null && touches.length > 0) { | ||
@@ -380,0 +397,0 @@ return touches[0]; |
@@ -53,3 +53,4 @@ const DELAY = "DELAY"; | ||
const isValidKeyPress = (event) => { | ||
const key = event.key, target = event.target; | ||
const key = event.key; | ||
const target = event.target; | ||
const role = target.getAttribute("role"); | ||
@@ -149,3 +150,4 @@ const isSpacebar = key === " " || key === "Spacebar"; | ||
const disabled = this._config.disabled; | ||
const key = event.key, target = event.target; | ||
const key = event.key; | ||
const target = event.target; | ||
if (!disabled && isValidKeyPress(event)) { | ||
@@ -187,3 +189,6 @@ if (this._touchState === NOT_RESPONDER) { | ||
onResponderTerminationRequest: (event) => { | ||
const _this$_config = this._config, cancelable = _this$_config.cancelable, disabled = _this$_config.disabled, onLongPress = _this$_config.onLongPress; | ||
const _this$_config = this._config; | ||
const cancelable = _this$_config.cancelable; | ||
const disabled = _this$_config.disabled; | ||
const onLongPress = _this$_config.onLongPress; | ||
if (!disabled && onLongPress != null && this._isPointerTouch && event.nativeEvent.type === "contextmenu") { | ||
@@ -198,3 +203,5 @@ return false; | ||
onClick: (event) => { | ||
const _this$_config2 = this._config, disabled = _this$_config2.disabled, onPress = _this$_config2.onPress; | ||
const _this$_config2 = this._config; | ||
const disabled = _this$_config2.disabled; | ||
const onPress = _this$_config2.onPress; | ||
if (!disabled) { | ||
@@ -214,3 +221,5 @@ event.stopPropagation(); | ||
onContextMenu: (event) => { | ||
const _this$_config3 = this._config, disabled = _this$_config3.disabled, onLongPress = _this$_config3.onLongPress; | ||
const _this$_config3 = this._config; | ||
const disabled = _this$_config3.disabled; | ||
const onLongPress = _this$_config3.onLongPress; | ||
if (!disabled) { | ||
@@ -240,3 +249,3 @@ if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) { | ||
console.error( | ||
"PressResponder: Invalid signal " + signal + " for state " + prevState + " on responder" | ||
`PressResponder: Invalid signal ${signal} for state ${prevState} on responder` | ||
); | ||
@@ -271,7 +280,9 @@ } else if (prevState !== nextState) { | ||
if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) { | ||
const _this$_config4 = this._config, _onLongPress = _this$_config4.onLongPress, onPress = _this$_config4.onPress; | ||
const _this$_config4 = this._config; | ||
const _onLongPress = _this$_config4.onLongPress; | ||
const onPress = _this$_config4.onPress; | ||
if (onPress != null) { | ||
const isPressCanceledByLongPress = _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START; | ||
if (!isPressCanceledByLongPress) { | ||
if (!isNextActive && !isPrevActive) { | ||
if (!(isNextActive || isPrevActive)) { | ||
this._activate(event); | ||
@@ -286,3 +297,5 @@ this._deactivate(event); | ||
_activate(event) { | ||
const _this$_config5 = this._config, onPressChange = _this$_config5.onPressChange, onPressStart = _this$_config5.onPressStart; | ||
const _this$_config5 = this._config; | ||
const onPressChange = _this$_config5.onPressChange; | ||
const onPressStart = _this$_config5.onPressStart; | ||
const touch = getTouchFromResponderEvent(event); | ||
@@ -301,3 +314,5 @@ this._touchActivatePosition = { | ||
_deactivate(event) { | ||
const _this$_config6 = this._config, onPressChange = _this$_config6.onPressChange, onPressEnd = _this$_config6.onPressEnd; | ||
const _this$_config6 = this._config; | ||
const onPressChange = _this$_config6.onPressChange; | ||
const onPressEnd = _this$_config6.onPressEnd; | ||
function end() { | ||
@@ -354,3 +369,5 @@ if (onPressEnd != null) { | ||
function getTouchFromResponderEvent(event) { | ||
const _event$nativeEvent = event.nativeEvent, changedTouches = _event$nativeEvent.changedTouches, touches = _event$nativeEvent.touches; | ||
const _event$nativeEvent = event.nativeEvent; | ||
const changedTouches = _event$nativeEvent.changedTouches; | ||
const touches = _event$nativeEvent.touches; | ||
if (touches != null && touches.length > 0) { | ||
@@ -357,0 +374,0 @@ return touches[0]; |
{ | ||
"name": "@tamagui/react-native-use-pressable", | ||
"version": "1.0.1-rc.5.1", | ||
"version": "1.0.1-rc.6", | ||
"types": "./types/index.d.ts", | ||
@@ -15,4 +15,4 @@ "main": "dist/cjs", | ||
"watch": "tamagui-build --watch", | ||
"lint": "eslint src", | ||
"lint:fix": "yarn lint --fix", | ||
"lint": "../../node_modules/.bin/rome check src", | ||
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src", | ||
"clean": "tamagui-build clean", | ||
@@ -25,3 +25,3 @@ "clean:build": "tamagui-build clean:build" | ||
"devDependencies": { | ||
"@tamagui/build": "^1.0.1-rc.5.1", | ||
"@tamagui/build": "^1.0.1-rc.6", | ||
"@types/react": "^18.0.15" | ||
@@ -28,0 +28,0 @@ }, |
@@ -61,3 +61,4 @@ /** | ||
const isActiveSignal = (signal) => | ||
signal === RESPONDER_ACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_LONG_PRESS_START | ||
signal === RESPONDER_ACTIVE_PRESS_START || | ||
signal === RESPONDER_ACTIVE_LONG_PRESS_START | ||
@@ -71,7 +72,8 @@ const isButtonRole = (element) => element.getAttribute('role') === 'button' | ||
const isTerminalSignal = (signal) => signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE | ||
const isTerminalSignal = (signal) => | ||
signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE | ||
const isValidKeyPress = (event) => { | ||
const key = event.key, | ||
target = event.target | ||
const key = event.key | ||
const target = event.target | ||
const role = target.getAttribute('role') | ||
@@ -218,3 +220,3 @@ const isSpacebar = key === ' ' || key === 'Spacebar' | ||
0, | ||
DEFAULT_PRESS_DELAY_MS | ||
DEFAULT_PRESS_DELAY_MS, | ||
) | ||
@@ -233,3 +235,3 @@ | ||
10, | ||
DEFAULT_LONG_PRESS_DELAY_MS | ||
DEFAULT_LONG_PRESS_DELAY_MS, | ||
) | ||
@@ -284,4 +286,4 @@ this._longPressDelayTimeout = setTimeout(() => { | ||
const disabled = this._config.disabled | ||
const key = event.key, | ||
target = event.target | ||
const key = event.key | ||
const target = event.target | ||
@@ -335,6 +337,6 @@ if (!disabled && isValidKeyPress(event)) { | ||
onResponderTerminationRequest: (event) => { | ||
const _this$_config = this._config, | ||
cancelable = _this$_config.cancelable, | ||
disabled = _this$_config.disabled, | ||
onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default | ||
const _this$_config = this._config | ||
const cancelable = _this$_config.cancelable | ||
const disabled = _this$_config.disabled | ||
const onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default | ||
// behavior will be prevented for non-mouse pointers. | ||
@@ -366,5 +368,5 @@ | ||
onClick: (event) => { | ||
const _this$_config2 = this._config, | ||
disabled = _this$_config2.disabled, | ||
onPress = _this$_config2.onPress | ||
const _this$_config2 = this._config | ||
const disabled = _this$_config2.disabled | ||
const onPress = _this$_config2.onPress | ||
@@ -391,8 +393,12 @@ if (!disabled) { | ||
onContextMenu: (event) => { | ||
const _this$_config3 = this._config, | ||
disabled = _this$_config3.disabled, | ||
onLongPress = _this$_config3.onLongPress | ||
const _this$_config3 = this._config | ||
const disabled = _this$_config3.disabled | ||
const onLongPress = _this$_config3.onLongPress | ||
if (!disabled) { | ||
if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) { | ||
if ( | ||
onLongPress != null && | ||
this._isPointerTouch && | ||
!event.defaultPrevented | ||
) { | ||
event.preventDefault() | ||
@@ -429,3 +435,3 @@ event.stopPropagation() | ||
console.error( | ||
'PressResponder: Invalid signal ' + signal + ' for state ' + prevState + ' on responder' | ||
`PressResponder: Invalid signal ${signal} for state ${prevState} on responder`, | ||
) | ||
@@ -476,5 +482,5 @@ } else if (prevState !== nextState) { | ||
if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) { | ||
const _this$_config4 = this._config, | ||
_onLongPress = _this$_config4.onLongPress, | ||
onPress = _this$_config4.onPress | ||
const _this$_config4 = this._config | ||
const _onLongPress = _this$_config4.onLongPress | ||
const onPress = _this$_config4.onPress | ||
@@ -487,3 +493,3 @@ if (onPress != null) { | ||
// If we never activated (due to delays), activate and deactivate now. | ||
if (!isNextActive && !isPrevActive) { | ||
if (!(isNextActive || isPrevActive)) { | ||
this._activate(event) | ||
@@ -501,5 +507,5 @@ | ||
_activate(event) { | ||
const _this$_config5 = this._config, | ||
onPressChange = _this$_config5.onPressChange, | ||
onPressStart = _this$_config5.onPressStart | ||
const _this$_config5 = this._config | ||
const onPressChange = _this$_config5.onPressChange | ||
const onPressStart = _this$_config5.onPressStart | ||
const touch = getTouchFromResponderEvent(event) | ||
@@ -521,5 +527,5 @@ this._touchActivatePosition = { | ||
_deactivate(event) { | ||
const _this$_config6 = this._config, | ||
onPressChange = _this$_config6.onPressChange, | ||
onPressEnd = _this$_config6.onPressEnd | ||
const _this$_config6 = this._config | ||
const onPressChange = _this$_config6.onPressChange | ||
const onPressEnd = _this$_config6.onPressEnd | ||
@@ -591,5 +597,5 @@ function end() { | ||
function getTouchFromResponderEvent(event) { | ||
const _event$nativeEvent = event.nativeEvent, | ||
changedTouches = _event$nativeEvent.changedTouches, | ||
touches = _event$nativeEvent.touches | ||
const _event$nativeEvent = event.nativeEvent | ||
const changedTouches = _event$nativeEvent.changedTouches | ||
const touches = _event$nativeEvent.touches | ||
@@ -596,0 +602,0 @@ if (touches != null && touches.length > 0) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117083
1518