When to use TouchableNativeFeedback, TouchableHighlight or TouchableOpacity?

前端 未结 4 614
深忆病人
深忆病人 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:17

    Well, This is how I typically decide what to use:

    • If I'm building for Android-only, and the component is large enough that the native feedback will be visibly different than using the others then I use TouchableNativeFeedback
    • If I want to control the opacity on the component or I want the button to have color when touched, and I don't want to control the focused state of some element inside the Touchable, then I use TouchableHighlight. (TouchableOpacity has got some weird parts when you control opacity yourself).
    • In all other cases, I use TouchableOpacity because it's more "bare" than TouchableHighlight

提交回复
热议问题