Skip to content

Commit

Permalink
Replace Text with RN component when callbacks are not specified (#3336
Browse files Browse the repository at this point in the history
)

## Description

This PR replaces our `Text` component with default RN component, when `onPress` or `onLongPress` callbacks are not provided.

Should help with #3331

## Test plan

Tested on code from _**NestedText**_ example with variations:

Additional `View`/`Text` inside `Touchable`, with/without `onPress` on outer `Text`.
  • Loading branch information
m-bert authored Jan 20, 2025
1 parent a358ab0 commit 5f3211d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { GestureDetector } from '../handlers/gestures/GestureDetector';

export const Text = forwardRef(
(props: RNTextProps, ref: ForwardedRef<RNText>) => {
const { onPress, ...rest } = props;
const { onPress, onLongPress, ...rest } = props;

const textRef = useRef<RNText | null>(null);
const native = Gesture.Native().runOnJS(true);

Expand Down Expand Up @@ -50,10 +51,17 @@ export const Text = forwardRef(
);
}, []);

return (
return onPress || onLongPress ? (
<GestureDetector gesture={native}>
<RNText onPress={onPress} ref={refHandler} {...rest} />
<RNText
onPress={onPress}
onLongPress={onLongPress}
ref={refHandler}
{...rest}
/>
</GestureDetector>
) : (
<RNText ref={ref} {...rest} />
);
}
);
Expand Down

0 comments on commit 5f3211d

Please sign in to comment.