In React Native, there are at least three ways to make a button: TouchableNativeFeedback
, TouchableHighlight
and TouchableOpacity
. There is also TouchableWithoutFeedback
, which the documentation clearly states you should not use because "all the elements that respond to press should have a visual feedback when touched".
Are there any other significant differences between the three? Is one of them the goto component? In what case should you use TouchableHighlight
over TouchableOpacity
? Are there any performance implications?
I am writing an application right now, and find that all three have a significant delay between tap and the action (in this case a navigation change). Is there any way to make it snappier?
TouchableHighlight is a component that is used to provide a wrapper to Views in order to make them respond correctly to touch-based input. On press down the TouchableHighlight component has its opacity decreased which allows the underlying View or other component's style to get highlighted.
A wrapper for making views respond properly to touches (Android only). On Android this component uses native state drawable to display touch feedback.
This component fades out when pressed, and fades back in when released. We can style it however we want, just like a View . We can configure the pressed opacity with the activeOpacity prop.
Touchables If the basic button doesn't look right for your app, you can build your own button using any of the "Touchable" components provided by React Native. The "Touchable" components provide the capability to capture tapping gestures, and can display feedback when a gesture is recognized.
source: https://medium.com/differential/better-cross-platform-react-native-components-cb8aadeba472, by Nick Wientge
TouchableHighlight
• What it does: Darkens or lightens the background of the element when pressed.
• When to use it: On iOS for touchable elements or buttons that have a solid shape or background, and on ListView items.
TouchableOpacity
• What it does: Lightens the opacity of the entire element when pressed.
• When to use it: On iOS for touchable elements that are standalone text or icons with no background color.
TouchableNativeFeedback
• What it does: Adds a ripple effect to the background when pressed.
• When to use it: On Android for almost all touchable elements.
Well, This is how I typically decide what to use:
TouchableNativeFeedback
TouchableHighlight
. (TouchableOpacity
has got some weird parts when you control opacity yourself).TouchableOpacity
because it's more "bare" than TouchableHighlight
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With