[英]My TouchableOpacity is not working in react-native
I have just started React-Native.我刚刚开始使用 React-Native。 But here my TouchableOpacity is not working.please check the code
但是这里我的 TouchableOpacity 不工作。请检查代码
import React, { Component } from 'react'
import { View, Text , StyleSheet, TouchableOpacity, TouchableNativeFeedback } from 'react-native'
import firebase from 'firebase'
class Article extends Component {
handleOnPress = () => {
firebase.auth().signOut();
}
render(){
return (
<View style={styles.container}>
<View >
<Text>You are logged in </Text>
<TouchableOpacity style={styles.buttonContainer}
onPress={this.handleOnPress}>
<Text>Log Out</Text>
</TouchableOpacity>
</View>
</View>
)}
}
export default Article
const styles = StyleSheet.create({
container:{
flex:1,
justifyContent:'center',
alignItems:'center',
backgroundColor:'red'
},
button:{
color:'white',
justifyContent:'center',
alignItems:'center',
textAlign:'center',
fontWeight:'bold',
fontSize:25
},
buttonContainer:{
backgroundColor:'green',
color:'white',
padding:10,
borderRadius:8,
width:300,
height:50,
textAlign:'center',
padding:10,
alignSelf:'center',
marginTop:50
}
}
)
Try this:试试这个:
import React, { Component } from 'react'
import { View, Text , StyleSheet, TouchableOpacity} from 'react-native'
import firebase from 'firebase'
export default class Article extends Component {
handleOnPress = () => {
alert('Called') //just to see if the function it's called
firebase.auth().signOut();
}
render() {
return (
<View style={styles.container}>
<Text>You are logged in </Text>
<TouchableOpacity style={styles.buttonContainer} onPress={this.handleOnPress}>
<Text>Log Out</Text>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
container:{
flex:1,
justifyContent:'center',
alignItems:'center',
backgroundColor:'red'
},
button:{
color:'white',
justifyContent:'center',
alignItems:'center',
textAlign:'center',
fontWeight:'bold',
fontSize:25
},
buttonContainer:{
backgroundColor:'green',
color:'white',
padding:10,
borderRadius:8,
width:300,
height:50,
textAlign:'center',
padding:10,
alignSelf:'center',
marginTop:50
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.