Nativebase: Change button background color on press in

Created on 24 Jul 2016  路  8Comments  路  Source: GeekyAnts/NativeBase

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.

enhancement

All 8 comments

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.

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.

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

Added in latest release.

Please, how do I do this?

Hi @sankhadeeproy007 ,

How can i add overlay to touchable highlight

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 (
activeOpacity={1}
style={
this.state.pressStatus
? styles.buttonPress
: styles.button
}
onHideUnderlay={()=>this._onHideUnderlay()}
onShowUnderlay={()=>this._onShowUnderlay()}
>
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
}
});

@ajuajas Use underlayColor and activeOpacity

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcpracht picture mcpracht  路  3Comments

elnygren picture elnygren  路  3Comments

muthuraman007 picture muthuraman007  路  3Comments

nschurmann picture nschurmann  路  3Comments

aloifolia picture aloifolia  路  3Comments