Skip to main content
Version: 3.x

Touchable

note

This section refers to new Touchable component, meant to replace both buttons and touchables. If you are looking for documentation for the deprecated touchable components, check out the Legacy Touchables section.

Touchable is a versatile new component introduced in Gesture Handler 3 to supersede previous button implementations. Designed for maximum flexibility, it provides a highly customizable interface for native touch handling while ensuring consistent behavior across platforms.

Touchable provides a simple interface for the common animations like opacity, underlay, and scale, implemented entirely on the platform. On Android, it also exposes the native ripple effect on press (turned off by default).

If the provided animations are not sufficient, it's possible to use Touchable to create fully custom interactions using either Reanimated or Animated API.

Replacing old buttons

If you were using RectButton or BorderlessButton in your app, you should replace them with Touchable. Check out the full code in the example section below.

RectButton

To replace RectButton with Touchable, simply add activeUnderlayOpacity={0.105} to your Touchable. This will animate the underlay when the button is pressed.

<Touchable
...
activeUnderlayOpacity={0.105}/>

BorderlessButton

Replacing BorderlessButton with Touchable is as easy as replacing RectButton. Just add activeOpacity={0.3} to your Touchable. This will animate the whole component when the button is pressed.

<Touchable
...
activeOpacity={0.3}/>

Migrating from legacy Touchable variants

If you were using the specialized touchable components (TouchableOpacity, TouchableHighlight, TouchableWithoutFeedback, or TouchableNativeFeedback), you can replicate their behavior with the unified Touchable component.

TouchableOpacity

To replace TouchableOpacity, add activeOpacity={0.2}.

<Touchable
...
activeOpacity={0.2}/>

TouchableHighlight

To replace TouchableHighlight, add activeUnderlayOpacity={1}.

<Touchable
...
activeUnderlayOpacity={1}/>

TouchableWithoutFeedback

To replace TouchableWithoutFeedback, use a plain Touchable.

<Touchable ... />

TouchableNativeFeedback

To replicate TouchableNativeFeedback behavior, use the androidRipple prop. Make sure to set foreground={true}.

<Touchable
...
androidRipple={{
foreground: true,
}}/>

Example

In this example we will demonstrate how to recreate RectButton and BorderlessButton effects using the Touchable component.


export default function TouchableExample() {
return (
<GestureHandlerRootView style={styles.container}>
<Touchable
onPress={() => {
console.log('BaseButton built with Touchable');
}}
style={[styles.button, { backgroundColor: '#7d63d9' }]}>
<Text style={styles.buttonText}>BaseButton</Text>
</Touchable>

<Touchable
onPress={() => {
console.log('RectButton built with Touchable');
}}
style={[styles.button, { backgroundColor: '#4f9a84' }]}
activeUnderlayOpacity={0.105}>
<Text style={styles.buttonText}>RectButton</Text>
</Touchable>

<Touchable
onPress={() => {
console.log('BorderlessButton built with Touchable');
}}
style={[styles.button, { backgroundColor: '#5f97c8' }]}
activeOpacity={0.3}>
<Text style={styles.buttonText}>BorderlessButton</Text>
</Touchable>
</GestureHandlerRootView>
);
}

const styles = StyleSheet.create({

Properties

activeOpacity

activeOpacity?: number;

Defines the opacity of the whole component when the button is active.

defaultOpacity

defaultOpacity?: number;

Defines the opacity of the whole component when the button is active. By default set to 1.

activeUnderlayOpacity

activeUnderlayOpacity?: number;

Defines the opacity of the underlay when the button is active. By default set to 0.

defaultUnderlayOpacity

defaultUnderlayOpacity?: number;

Defines the initial opacity of underlay when the button is inactive. By default set to 0.

underlayColor

underlayColor?: string;

Background color of the underlay. This only takes effect when activeUnderlayOpacity or defaultUnderlayOpacity is set.

exclusive

exclusive?: boolean;

Defines whether pressing this button prevents other buttons exported by Gesture Handler from being pressed. By default set to true.

touchSoundDisabled

Android
touchSoundDisabled?: boolean;

If set to true, the system will not play a sound when the button is pressed.

onPressIn


onPressIn?: (e: GestureEvent<NativeHandlerData>) => void;

Triggered when the button gets pressed (analogous to onPressIn in Pressable from RN core).

onPressOut


onPressOut?: (e: GestureEvent<NativeHandlerData>) => void;

Triggered when the button gets released or the pointer moves outside of the button area (analogous to onPressOut in Pressable from RN core).

onPress

onPress?: (pointerInside: boolean) => void;

Triggered when the button gets pressed (analogous to onPress in Pressable from RN core).

onLongPress

onLongPress?: () => void;

Triggered when the button gets pressed for at least delayLongPress milliseconds.

onActiveStateChange

onActiveStateChange?: (active: boolean) => void;

Triggered when the button transitions between active and inactive states. It passes the current active state as a boolean variable to the method as the first parameter.

delayLongPress

delayLongPress?: number;

Defines the delay, in milliseconds, after which the onLongPress callback gets called. By default set to 600.

androidRipple

Android

androidRipple?: PressableAndroidRippleConfig;

Configuration for the ripple effect on Android. If not provided, the ripple effect will be disabled. If {} is provided, the ripple effect will be enabled with default configuration.