Skip to content

refactor TouchableOpacity forwarding event on onPress and onLongPress #2462

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

Merged
merged 3 commits into from
Feb 12, 2023

Conversation

AmitShwarts
Copy link
Contributor

Description

change the way we forward the event to onPress and onLongPress handler to send event along with props, instead spreading the event together with props

Changelog

refactor TouchableOpacity forwarding event on onPress and onLongPress

@@ -155,12 +159,12 @@ class TouchableOpacity extends PureComponent<Props, {active: boolean}> {
);
}

onPress(event: BaseSyntheticEvent) {
this.props.onPress?.({...this.props, ...event});
onPress(event: GestureResponderEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you changed it from BaseSyntheticEvent to GestureResponderEvent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the correct typing in React Native:

    onLongPress?: ((event: GestureResponderEvent) => void) | undefined;

    /**
     * Called when the touch is released,
     * but not if cancelled (e.g. by a scroll that steals the responder lock).
     */
    onPress?: ((event: GestureResponderEvent) => void) | undefined;

    onPressIn?: ((event: GestureResponderEvent) => void) | undefined;

    onPressOut?: ((event: GestureResponderEvent) => void) | undefined;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, please just verify it's the same type for web events (you can run the web demo with this change).
I thought you picked the BaseSyntheticEvent last time for that reason

@lidord-wix lidord-wix enabled auto-merge (squash) February 12, 2023 16:07
@lidord-wix lidord-wix merged commit 4d6f3b6 into master Feb 12, 2023
@AmitShwarts AmitShwarts deleted the refactor-touchable-opacity-event-on-press branch February 12, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants