Skip to content

Fix LegacyPressable#4016

Merged
m-bert merged 3 commits into
mainfrom
@mbert/legacy-pressable
Mar 6, 2026
Merged

Fix LegacyPressable#4016
m-bert merged 3 commits into
mainfrom
@mbert/legacy-pressable

Conversation

@m-bert

@m-bert m-bert commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

Description

LegacyPressable does not work as underlying button implementation had changed. Because previous button is still accessible, I've changed LegacyPressable to use it instead of new one, bringing back old behavior.

On web it required some changes as buttons are exported as export default, so simply changing non-web button and import in Pressable caused crash on web.

I've also removed forwardedRef from web button and fixed button example so it doesn't always indicate onLongPress.

Test plan

Tested on expo-example, on examples with Pressable and Buttons example

Copilot AI review requested due to automatic review settings March 5, 2026 09:43
* Invoked on mount and layout changes.
*/
onLayout?: (event: LayoutChangeEvent) => void;
onLayout?: ((event: LayoutChangeEvent) => void) | undefined;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is necessary because of #4012

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR restores LegacyPressable behavior by switching it back to using the underlying (older) button implementation, and adjusts web exports to avoid crashes stemming from default-vs-named export differences.

Changes:

  • Update LegacyPressable to use GestureHandlerButton’s underlying ButtonComponent instead of the newer wrapper implementation.
  • Export ButtonComponent from GestureHandlerButton (native) and align web exports to support named imports.
  • Fix the common-app buttons example to report onPress correctly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx Switches LegacyPressable to use the underlying ButtonComponent to restore legacy behavior.
packages/react-native-gesture-handler/src/components/GestureHandlerButton.web.tsx Introduces named export + default export alignment for web button component.
packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx Exposes the underlying native ButtonComponent for internal reuse (e.g., by LegacyPressable).
apps/common-app/src/new_api/components/buttons/index.tsx Fixes example feedback string so onPress doesn’t report as onLongPress.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@akwasniewski akwasniewski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.
However, can we choose this opportunity to change button component import names in Pressable? Currently ButtonComponent is imported as

ViewStyle,
} from 'react-native';
import NativeButton from '../GestureHandlerButton';
import { ButtonComponent as NativeButton } from '../GestureHandlerButton';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a remark, you don't have to change it if you don't think it's necessary: I think it would be sensible to simply change the name of the ButtonComponent to NativeButton. Also after changes in the ../GestureHandlerButton, the Button imported in the v3 version is the wrapped one, thus aliasing it as PureNativeButton seems weird, we can just remove the alias.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think we can leave it as it is for now and leave those renames for other PRs. This one already grew bigger than I expected 😅

@m-bert m-bert merged commit ee266bb into main Mar 6, 2026
4 checks passed
@m-bert m-bert deleted the @mbert/legacy-pressable branch March 6, 2026 08:50
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.

4 participants