Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
React-Native cambiando <Imagen/> fuente con estado

Estoy tratando de crear un componente React que alterna un logotipo entre blanco y negro cuando se presiona. Quiero incorporar más funciones en el componente en el futuro, pero changeLogo() console.log ni siquiera se mostrará en el depurador.

¡Cualquier ayuda/consejo apreciada!

reaccionar nativo: 0.39.2 reaccionar: ^ 15.4.2

 import React, { Component } from 'react'; import { View, Image } from 'react-native'; export default class TestButton extends Component { constructor(props) { super(props); this.state = { uri: require('./icons/logo_white.png') } } changeLogo() { console.log('state changed!'); this.setState({ uri: require('./icons/logo_black.png') }); } render() { return ( <View style={styles.container} > <Image source={this.state.uri} style={styles.logoStyle} onPress={this.changeLogo} /> </View> ); } } const styles = { container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue', }, logoStyle: { width: 200, height: 200, marginLeft: 10, marginRight: 5, alignSelf: 'center', }, };
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

onPress prop no está disponible para el componente Imagen . Debe envolverlo con el componente TouchableHighlight de esta manera:

 import { View, Image, TouchableHighlight } from 'react-native'; ... <TouchableHighlight onPress={() => this.changeLogo()}> <Image source={this.state.uri} style={styles.logoStyle} /> </TouchableHighlight>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!