jaredh159 / tailwind-react-native-classnames

simple, expressive API for tailwindcss + react-native
2.03k stars 82 forks source link

How to style pressed event of a pressable #305

Closed Ali-Aref closed 3 months ago

Ali-Aref commented 4 months ago

This is my Pressable with the Stylesheet api

<Pressable
    style={({ pressed }) => [{ 
        opacity: pressed ? 0.5 : 1.0 }
    ]}>
    <Text>SOme teXt</Text>
</Pressable>

how to style that using twrnc ? I want to change the background and border colors when the button is pressed.

jaredh159 commented 3 months ago

this should work:

<Pressable
  style={({ pressed }) => [tw.style(pressed ? `bg-black` : `bg-white`)]}
>
  <Text>Press me</Text>
</Pressable>