Professional Documents
Culture Documents
Touchable components provide the capability to capture the tapping functionality. The
touchables component can be implemented as an alternative of basic button, if they are
not look right for your app. Using these components, you build your own button.
Tapping on these components, you can display the feedback.
The touchables components do not provide any default styling, so you will need to do
your style for presenting nicely in the app.
o TouchableHighlight
o TouchableNativeFeedback
o TouchableOpacity
o TouchableWithoutFeedback.
Props
Props Type Requi Platf Description
red orm
it is touched.
underlayColor color no Show the underlay color when the touch is active.
Props
Props Type Required Description
Methods
Method Description
Props
Props Type Required Description
hitSlop object no This defines how far your touch can start away from the button.
onAccessibilityTa functio no If accessible is set to true, the system invokes this function
p n
when the user performs accessibility tap gesture.
Some time user presses a view and holds it for the set of time. This long press is handled
by the function using onLongPress props of any of the above "Touchable" components.
CODE
_onLongPressButton() {
Alert.alert('You long-pressed the button!')
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this._onPressButton} underlayColor="white">
<View style={styles.button}>
<Text style={styles.buttonText}>TouchableHighlight</Text>
</View>
</TouchableHighlight>
<TouchableOpacity onPress={this._onPressButton}>
<View style={styles.button}>
<Text style={styles.buttonText}>TouchableOpacity</Text>
</View>
</TouchableOpacity>
<TouchableNativeFeedback
onPress={this._onPressButton}
background={Platform.OS === 'android' ? TouchableNativeFeedback.SelectableBackground() :
''}>
<View style={styles.button}>
<Text style={styles.buttonText}>TouchableNativeFeedback</Text>
</View>
</TouchableNativeFeedback>
<TouchableWithoutFeedback
onPress={this._onPressButton}
>
<View style={styles.button}>
<Text style={styles.buttonText}>TouchableWithoutFeedback</Text>
</View>
</TouchableWithoutFeedback>
<TouchableHighlight onPress={this._onPressButton} onLongPress={this._onLongPressButton}
underlayColor="white">
<View style={styles.button}>
<Text style={styles.buttonText}>Touchable with Long Press</Text>
</View>
</TouchableHighlight>
</View>
);
}
}
Output:
import React, { useState } from "react";
import { StyleSheet, Text, TouchableHighlight, View } from
"react-native";
return (
<View style={styles.container}>
<TouchableHighlight onPress={onPress}>
<View style={styles.button}>
<Text>Touch Here</Text>
</View>
</TouchableHighlight>
<View style={styles.countContainer}>
<Text style={styles.countText}>
{count || null}
</Text>
</View>
</View>
);
}
return (
<View style={styles.container}>
<View style={styles.countContainer}>
<Text>Count: {count}</Text>
</View>
<TouchableOpacity
style={styles.button}
onPress={onPress}
>
<Text>Press Here</Text>
</TouchableOpacity>
</View>
);
};