NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Change button background color on press in

Open viper1029 opened this issue 10 years ago • 11 comments

Is there an way to change the color of the Button while the user is pressing it? Currently, its possible to make it more transparent, but not change the color.

viper1029 avatar Jul 24 '16 02:07 viper1029

Button is wrapped around TouchableOpacity, so setting onPress background color is not possible at the moment. I recommend the use of TouchableHighlight for your desired effect.

sankhadeeproy007 avatar Jul 24 '16 07:07 sankhadeeproy007

Hi, would like to change background color when button press too. Do you guys have any plan to implement using TouchableHighlight? Initially, I wanted to clone the same button using TouchableHighlight, but it seems like there are alot logics and libraries in the Button widget.

kuoliangkwong avatar Nov 03 '16 10:11 kuoliangkwong

We have added this to our roadmap. We will implement this in future versions.

himanshu-satija avatar Nov 03 '16 14:11 himanshu-satija

Added in latest release.

sankhadeeproy007 avatar Mar 22 '17 08:03 sankhadeeproy007

Please, how do I do this?

olowe avatar Jul 03 '17 10:07 olowe

Hi @sankhadeeproy007 ,

How can i add overlay to touchable highlight

ajuajas avatar Nov 22 '18 12:11 ajuajas

import React, { Component, StyleSheet, PropTypes, View, Text, TouchableHighlight } from "react-native";

export default class Home extends Component { constructor(props) { super(props); this.state = { pressStatus: false }; } _onHideUnderlay=()=> { this.setState({ pressStatus: false }); } _onShowUnderlay=()=> { this.setState({ pressStatus: true }); } render() { return ( <TouchableHighlight activeOpacity={1} style={ this.state.pressStatus ? styles.buttonPress : styles.button } onHideUnderlay={()=>this._onHideUnderlay()} onShowUnderlay={()=>this._onShowUnderlay()} > <Text style={ this.state.pressStatus ? styles.welcomePress : styles.welcome } > {this.props.text} ); } }

Home.propTypes = { text: PropTypes.string.isRequired };

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF" }, welcome: { fontSize: 20, textAlign: "center", margin: 10, color: "#000066" }, welcomePress: { fontSize: 20, textAlign: "center", margin: 10, color: "#ffffff" }, button: { borderColor: "#000066", borderWidth: 1, borderRadius: 10 }, buttonPress: { borderColor: "#000066", backgroundColor: "#000066", borderWidth: 1, borderRadius: 10 } });

embashgit avatar Jan 09 '19 21:01 embashgit

@ajuajas Use underlayColor and activeOpacity

<TouchableHighlight onPress={() => console.log("button pressed')} activeOpacity={0.6} underlayColor="#DDDDDD"> <Text> {"press me"} </Text> </TouchableHighlight>

Takesuma avatar Aug 11 '20 09:08 Takesuma

Button is wrapped around TouchableOpacity, so setting onPress background color is not possible at the moment. I recommend the use of TouchableHighlight for your desired effect.

We have added this to our roadmap. We will implement this in future versions.

@sankhadeeproy007 @himanshu-satija : Have we got any updates on this as an in-built prop for a Button native base component in the latest versions?

aniruddhashevle avatar Nov 06 '21 14:11 aniruddhashevle

this solution it work for me <Button _pressed={{backgroundColor: "#fff"}} w={width ? width : '100%'} size="lg" _text={{ color: theme.colors.white, fontSize: 'lg', fontFamily: 'bold', }} ref={myRef} onPress={onPress}> {title}

NabilBenOun1 avatar Oct 19 '22 14:10 NabilBenOun1

Do we have any update on this ?

sainijagjit avatar Dec 15 '22 10:12 sainijagjit