0
I have a TouchableOpacity
that when touching does not call the method alert()
in React Native, follow my code:
var data = []; export default class VerOs extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
fontLoaded: false,
listViewData: data
};
this.alerta = this.alerta.bind(this)
}
componentDidMount() {
this.carregaList(this)
this.alerta()
}
carregaList(that) {
var newData = []
FirebaseConfig.database().ref('/user').on('child_added', function (dat) {
newData.push(dat)
that.setState({
listViewData: newData,
isLoading: false
})
})
}
static navigationOptions = {
tabBarLabel: 'Ver O.S',
tabBarIcon: ({ tintColor }) => (
<Icon name='ios-aperture' color={tintColor} size={24} />
)
}
alerta(){
console.log("texto")
}
renderItem({ item }) {
return (
<TouchableOpacity onPress={this.alerta} > //AQUI NÃO CHAMA
<ListItem
title={item.val().name}
subtitle={item.val().name}
leftAvatar={{ source: { uri: item.val().age } }} />
</TouchableOpacity>
)
}
render() {
if (this.state.isLoading) {
return (
<View style={styles.container}>
<ActivityIndicator size="large" animating />
</View>
)
} else {
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name='ios-menu' color={"#fff"} size={24} />
</Button>
</Left>
<Body>
<Title>Header</Title>
</Body>
<Right />
</Header>
<Content>
<FlatList
data={this.state.listViewData}
renderItem={this.renderItem} />
</Content>
</Container>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
So if you open the debug in the browser you will see yours
console.log
la, all right with your code, now if you want an Alert on the screen there I suggest changing theconsole.log('texto)
foralert('texto')
– Chance
So the code is correct? The console also does not appear.
– Emerson Barcellos
So the way onpress is used yes, there may be a problem in how the list is mounted in Flatlist, I will test your code to see, soon return.
– Chance
Okay buddy I’ll check the bottom. Thank you
– Emerson Barcellos