diff --git a/packages/react-native/Libraries/Components/TextInput/TextInput.js b/packages/react-native/Libraries/Components/TextInput/TextInput.js index 6f0ff252332..dcf11237599 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInput.js +++ b/packages/react-native/Libraries/Components/TextInput/TextInput.js @@ -1539,7 +1539,7 @@ function InternalTextInput(props: Props): React.Node { // TextInput handles onBlur and onFocus events // so omitting onBlur and onFocus pressability handlers here. - const {onBlur, onFocus, ...eventHandlers} = usePressability(config) || {}; + const {onBlur, onFocus, ...eventHandlers} = usePressability(config); let _accessibilityState; if ( diff --git a/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js b/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js index 1f85edcb1a9..d584a2f8623 100755 --- a/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js +++ b/packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js @@ -195,8 +195,7 @@ module.exports = function TouchableWithoutFeedback(props: Props): React.Node { // BACKWARD-COMPATIBILITY: Focus and blur events were never supported before // adopting `Pressability`, so preserve that behavior. - const {onBlur, onFocus, ...eventHandlersWithoutBlurAndFocus} = - eventHandlers || {}; + const {onBlur, onFocus, ...eventHandlersWithoutBlurAndFocus} = eventHandlers; const elementProps: {[string]: mixed, ...} = { ...eventHandlersWithoutBlurAndFocus, diff --git a/packages/react-native/Libraries/Pressability/usePressability.js b/packages/react-native/Libraries/Pressability/usePressability.js index 3f2aebb4461..9a8f9666c6e 100644 --- a/packages/react-native/Libraries/Pressability/usePressability.js +++ b/packages/react-native/Libraries/Pressability/usePressability.js @@ -14,6 +14,9 @@ import Pressability, { } from './Pressability'; import {useEffect, useRef} from 'react'; +declare function usePressability(config: PressabilityConfig): EventHandlers; +declare function usePressability(config: null | void): null | EventHandlers; + /** * Creates a persistent instance of `Pressability` that automatically configures * itself and resets. Accepts null `config` to support lazy initialization. Once @@ -28,7 +31,7 @@ import {useEffect, useRef} from 'react'; */ export default function usePressability( config: ?PressabilityConfig, -): ?EventHandlers { +): null | EventHandlers { const pressabilityRef = useRef(null); if (config != null && pressabilityRef.current == null) { pressabilityRef.current = new Pressability(config); diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 2639b859abe..852f9da15d1 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -7233,7 +7233,7 @@ exports[`public API should not change unintentionally Libraries/Pressability/Pre exports[`public API should not change unintentionally Libraries/Pressability/usePressability.js 1`] = ` "declare export default function usePressability( config: ?PressabilityConfig -): ?EventHandlers; +): null | EventHandlers; " `;