Skip to content

Commit ee266bb

Browse files
authored
Fix LegacyPressable (#4016)
## 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
1 parent 864cffe commit ee266bb

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

apps/common-app/src/new_api/components/buttons/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function ButtonWrapper({
2929
<ButtonComponent
3030
style={[styles.button, { backgroundColor: color }]}
3131
onPress={() =>
32-
feedback?.current?.showMessage(`[${ButtonComponent.name}] onLongPress`)
32+
feedback?.current?.showMessage(`[${ButtonComponent.name}] onPress`)
3333
}
3434
onLongPress={() => {
3535
feedback?.current?.showMessage(`[${ButtonComponent.name}] onLongPress`);

packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface ButtonProps extends ViewProps, AccessibilityProps {
7070
/**
7171
* Invoked on mount and layout changes.
7272
*/
73-
onLayout?: (event: LayoutChangeEvent) => void;
73+
onLayout?: ((event: LayoutChangeEvent) => void) | undefined;
7474

7575
/**
7676
* Used for testing-library compatibility, not passed to the native component.
@@ -101,7 +101,7 @@ export interface ButtonProps extends ViewProps, AccessibilityProps {
101101
testOnly_onLongPress?: Function | null | undefined;
102102
}
103103

104-
const ButtonComponent =
104+
export const ButtonComponent =
105105
RNGestureHandlerButtonNativeComponent as HostComponent<ButtonProps>;
106106

107107
export default function GestureHandlerButton({ style, ...rest }: ButtonProps) {
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as React from 'react';
2-
import { View } from 'react-native';
2+
import { View, ViewProps } from 'react-native';
33

4-
export default React.forwardRef<React.ComponentRef<typeof View>>(
5-
(props, ref) => <View ref={ref} accessibilityRole="button" {...props} />
4+
type ButtonProps = ViewProps & {
5+
ref?: React.Ref<React.ComponentRef<typeof View>>;
6+
};
7+
8+
export const ButtonComponent = (props: ButtonProps) => (
9+
<View accessibilityRole="button" {...props} />
610
);
11+
12+
export default ButtonComponent;

packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
StyleProp,
2020
ViewStyle,
2121
} from 'react-native';
22-
import NativeButton from '../GestureHandlerButton';
22+
import { ButtonComponent as NativeButton } from '../GestureHandlerButton';
2323
import {
2424
gestureToPressableEvent,
2525
addInsets,

0 commit comments

Comments
 (0)