Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const PressableWithTouchable = (props: PressableProps) => {
} = rest;
/* eslint-enable @typescript-eslint/no-unused-vars */

const [pressed, setPressed] = useState(testOnly_pressed ?? false);
const [pressed, setPressed] = useState(false);
const timers = useRef<Timers>({ press: null, hoverIn: null, hoverOut: null });
const dimensions = useRef<PressableDimensions>({ width: 0, height: 0 });

Expand Down Expand Up @@ -284,11 +284,18 @@ const PressableWithTouchable = (props: PressableProps) => {
}
: undefined;

// `testOnly_pressed` forces the pressed state for snapshots/tests. Derive the
// displayed value from it each render, keeping the interactive `pressed` state
// independent (seeded to false) so clearing the prop doesn't leave it stuck.
const displayPressed = testOnly_pressed ?? pressed;
Comment thread
m-bert marked this conversation as resolved.

const resolvedStyle =
typeof style === 'function' ? style({ pressed }) : style;
typeof style === 'function' ? style({ pressed: displayPressed }) : style;

const resolvedChildren =
typeof children === 'function' ? children({ pressed }) : children;
typeof children === 'function'
? children({ pressed: displayPressed })
: children;

return (
<Touchable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const StatefulPressable = (props: PressableProps) => {
...remainingProps
} = props;

const [pressedState, setPressedState] = useState(testOnly_pressed ?? false);
const [pressedState, setPressedState] = useState(false);

const longPressTimeoutRef = useRef<number | null>(null);
const pressDelayTimeoutRef = useRef<number | null>(null);
Expand Down Expand Up @@ -400,12 +400,17 @@ const StatefulPressable = (props: PressableProps) => {
const pointerStyle: StyleProp<ViewStyle> =
Platform.OS === 'web' ? { cursor: 'pointer' } : {};

// `testOnly_pressed` forces the pressed state for snapshots/tests. Derive the
// displayed value from it each render, keeping the interactive `pressedState`
// independent (seeded to false) so clearing the prop doesn't leave it stuck.
const displayPressed = testOnly_pressed ?? pressedState;
Comment thread
m-bert marked this conversation as resolved.

const styleProp =
typeof style === 'function' ? style({ pressed: pressedState }) : style;
typeof style === 'function' ? style({ pressed: displayPressed }) : style;

const childrenProp =
typeof children === 'function'
? children({ pressed: pressedState })
? children({ pressed: displayPressed })
: children;

const rippleColor = useMemo(() => {
Expand Down
Loading