Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN: Improve usePressability Return Type #47596

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +31,7 @@ import {useEffect, useRef} from 'react';
*/
export default function usePressability(
config: ?PressabilityConfig,
): ?EventHandlers {
): null | EventHandlers {
const pressabilityRef = useRef<?Pressability>(null);
if (config != null && pressabilityRef.current == null) {
pressabilityRef.current = new Pressability(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"
`;

Expand Down
Loading