Skip to content
tezvyn:
Menu

Touchable Components in React Native

Source: reactnative.devMediumHow cards are made

TouchableOpacity and siblings wrap views to give press feedback by dimming or highlighting. Use them for simple taps on buttons or list items. They inject extra Animated.View nodes that can silently break layout, and Pressable has superseded the entire family.

Why it exists

Before touchable wrappers existed, making a view respond to a tap required manually wiring gesture responders and visual feedback. The Touchable family was created to give developers drop-in components that handle the touch lifecycle and provide immediate visual confirmation, such as dimming or highlighting, without writing boilerplate animation code. This abstraction became the standard way to make any view interactive.

The mental model

Think of TouchableOpacity and its siblings as transparent electrical tape. You wrap them around any ordinary view to make it interactive, and they automatically show the user that the press registered by changing the view's appearance. The trade-off is that the tape adds an extra layer in the physical stack, which can shift what sits beneath it and alter your layout in unexpected ways.

How it works

TouchableOpacity wraps its children in an Animated.View to drive the opacity change. When a user presses down, the opacity of the wrapped view drops to the activeOpacity value, which defaults to 0.2. This means the view dims to 20 percent of its normal opacity while the finger is down. Because an extra Animated.View node is inserted into the component tree, the layout can be affected in ways that are not obvious from the JSX. TouchableHighlight and TouchableWithoutFeedback are siblings in the same family that offer different feedback styles, while TouchableNativeFeedback provides Android ripple effects. All of them abstract the underlying responder system.

When to use it

Reach for TouchableOpacity when you need a simple button or list row that gives immediate visual feedback and you do not need fine-grained control over press states. It is ideal for prototypes, internal tools, or legacy codebases where replacing every instance with Pressable is not practical. If you only care about a basic onPress callback and a dimming effect, it still works.

When not to use it

Do not use TouchableOpacity when you need to detect multiple press states, long presses, or hover interactions with a single component. Do not use it if the extra Animated.View wrapper is causing layout bugs such as unexpected flexbox behavior or sizing issues. The React Native documentation explicitly recommends Pressable for new projects because it is more extensive and future-proof. Migrating old touchables to Pressable removes the hidden layout node and gives you access to modern press callbacks.

One canonical example

A common use is wrapping a styled View to create a custom button. You import TouchableOpacity, wrap your text and icon container inside it, and set activeOpacity to 0.5 so the button dims noticeably on press. Because TouchableOpacity inserts an Animated.View, you should test that your padding and margin still behave as expected and that the parent flex layout does not shift. If you are starting a new screen today, the docs suggest using Pressable instead.

Interview question

Why can wrapping a view with TouchableOpacity silently break a parent flexbox layout?

  • a.It permanently sets the wrapped view's opacity to 0.2
  • b.It requires manual wiring of the gesture responder system
  • c.It inserts an extra Animated.View node into the component treeCorrect
  • d.It strips flex properties from the immediate child container
Why?

TouchableOpacity wraps its children in an Animated.View to animate dimming, and that injected node can alter flexbox sizing or spacing in ways that are not obvious from the JSX. Option A is tempting because 0.2 is the default activeOpacity value, but the dimming only occurs while the finger is pressed, not permanently.

Just read this? Test yourself on what you have been reading.

Read the original → reactnative.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react native — each one lists the topics its interview covers.

See open roles