change colour of touchableOpacity after press but stays

Viewed 24

Im making a check-in button in react native that darkens after being pressed. I've read alot of articles but they only explain how to change the colour right after pressing (then it goes back to original colour). Whereas I want the colour to stay changed. How would I do that?

1 Answers

You have to make a state of isPressed and based on that state, give your touchable different style.

  style={isPressed ? firstStyle : secondStyle}
  onPress={()=> setIsPressed(prev=>!prev)}
Related