jaredh159 / tailwind-react-native-classnames

simple, expressive API for tailwindcss + react-native
2.08k stars 84 forks source link

How to style pressed event of a pressable #305

Closed Ali-Aref closed 5 months ago

Ali-Aref commented 5 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 5 months ago

this should work:

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