When to use TouchableNativeFeedback, TouchableHighlight or TouchableOpacity?

前端 未结 4 651
深忆病人
深忆病人 2021-01-29 22:45

In React Native, there are at least three ways to make a button: TouchableNativeFeedback, TouchableHighlight and TouchableOpacity. There i

4条回答
  •  难免孤独
    2021-01-29 23:33

    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.

提交回复
热议问题