I have a small component and I am trying to trigger a function onPress. I first tried the following: onPress={this.slider} and I did not receive a console log, then I tried onPress={()=>{this.slider}} and still did not receive a console log. Finally I tried onPress={console.log("Hello")} and received a console log. So I am clearly not calling the Slider function properly. I am not sure what I am doing incorrectly - something silly I am sure. All help is appreciated.
class newWave extends Component {
state = {
format: "TTS"
}
slider = () => {
console.log("hi");
if (this.state.format === "TTS")
this.setState({ format: "Voice" })
else if (this.state.format === "Voice")
this.setState({ format: "TTS" })
}
render() {
return (
<View style={{height:"100%", width: "100%", flexDirection:"column", justifyContent: "center", alignItems:"center"}}>
<View style={{height: "75%", width:"75%", backgroundColor:"blue", borderRadius:20, flexDirection:"row", justifyContent:"flex-end"}}>
<View style ={{backgroundColor:"transparent", height: "10%", width:"30%", margin: "2%"}}>
<View style = {{backgroundColor:"orange", height: "100%", width:"100%", borderRadius: 20, flexDirection:"row", justifyContent:this.state.format==="TTS"?"flex-start":"flex-end", alignItems:"center"}}>
<View style = {{backgroundColor:"green", height: "98%", width:"75%", borderRadius: 20, marginLeft: "1%", marginRight: "1%"}} onPress={()=>{this.slider}}></View>
</View>
</View>
</View>
</View>
);
}
}
export default newWave;
Viewcomponent inButtonorTouchableOpacity