Skip to main content

TouchableHighlight

A press target that shows an underlay while you press it. The underlay is a background color, and the child gets a lower opacity on top of it, so the child looks darker. The press handling is the same as on Pressable.

import { StyleSheet, Text, TouchableHighlight, View } from 'react-native'

export function Row({ onOpen }) {
return (
<TouchableHighlight role="button" underlayColor="#e5e7eb" onPress={onOpen}>
<View style={styles.row}>
<Text>Open</Text>
</View>
</TouchableHighlight>
)
}

const styles = StyleSheet.create({
row: { padding: 16, backgroundColor: 'white' },
})

The child must be one element that takes a style, for example a View. Give the child an opaque background color. The underlay then shows through the child as its opacity drops. Without a child background, the underlay shows at full strength, as on native.

How the underlay works​

  • When a press starts, the element gets underlayColor as its background, and the child gets activeOpacity.
  • When the press ends, the underlay goes away. After onPress, it stays for delayPressOut milliseconds, so a short tap still shows it.
  • With no press handler (onPress, onPressIn, onPressOut, or onLongPress), there's no underlay.
  • The underlay changes render the component again, as on native.
  • While it isn't disabled, it shows the pointer cursor. A cursor in style wins.

Props​

PropOn the web
underlayColorThe background while pressed. The default is black.
activeOpacityThe opacity of the child while pressed. The default is 0.85.
onShowUnderlay, onHideUnderlayCalled when the underlay shows and when it goes away.
testOnly_pressedShows the underlay all the time.
onPress, onPressIn, onPressOut, onLongPressAs on Pressable. There's no minimum press duration, as on native.
delayPressIn, delayPressOut, delayLongPressThe press delays, in milliseconds.
onFocus, onBlurFocus events of the element. On native, TouchableHighlight doesn't call them.
disabledSets aria-disabled, takes the element out of the tab order, and stops every press.
focusableAs on native, the element is in the tab order only with onPress. false takes it out.
hitSlop, pressRetentionOffsetAs on Pressable.
rejectResponderTerminationtrue sets touch-action: none, so a scroll that starts on the element can't cancel the press.
onClick and the other DOM handlersWeb only. Your handler runs first, then the press handling.
View propsAs on View.
touchSoundDisabled, hasTVPreferredFocus, nextFocusDown and othersNative only. Accepted and ignored.

Ref​

The ref is the DOM element.