Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touchable Opacity onPressIn color change

I have the following code in my React-Native application.

     <TouchableOpacity
       // onPress={onPress}
       onPressIn={this.handlePressIn}
       onPressOut={this.handlePressOut}
       disabled={disabled}
       style={[
         styles.button,
         buttonStyle,
         this.buttonStyles(),
       ]}
       >
         <Text>Hello</Text>
       </TouchableOpacity> 

I want to change the color of TouchableOpacity when it is being pressed. So, in onPressIn, I changed the color to darkRed, but it display a light red or something similar to that. No dark color can be set there. What is the issue here? How can I change the color till I onPressOut? The color should be a dark one.

like image 366
Shashika Avatar asked Oct 19 '25 03:10

Shashika


1 Answers

Found the solution. Set your activeOpacity={1} in your TouchableOpacity.

<TouchableOpacity
    onPress={onPress}
    activeOpacity={1}
/>
like image 87
Shashika Avatar answered Oct 22 '25 05:10

Shashika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!