Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Images dynamically from state #3799

Closed
josev55 opened this issue Oct 30, 2015 · 3 comments
Closed

Load Images dynamically from state #3799

josev55 opened this issue Oct 30, 2015 · 3 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@josev55
Copy link

josev55 commented Oct 30, 2015

Hi everybody,

I have an issue where I try to change the image source from a change in the state object but it's not changing.
I have logged the value and it's changing but the image does not.

Here it's the code im using:

render() {
        var images = {
            playcircle: require('image!playcircle'),
            pausecircle: require('image!pausecircle')
        }
        return (
            <View style={[styles.container, {width: this.props.width - 10}]}>
                <TouchableOpacity onPress={this._playAudio.bind(this)}>
                    <Image source={images[this.state.playImage]} style={styles.img} />
                </TouchableOpacity>
                <View style={styles.textWrapper}>
                    <Text style={styles.txt}>{this.props.podTitle}</Text>
                </View>
            </View>
        );
    }
_playAudio() {
        var blockThis = this;
        debugger;
        if (!this.state.isPlaying) {
            JSAudioPlayer.play(this.props.url, true, function(error){
                if (error) {
                    alert(error);
                } else {
                    blockThis.setState({
                        isPlaying: true,
                        playImage: 'pausecircle'
                    })
                }
            });
        } else {
            JSAudioPlayer.pauseCurrent();
            blockThis.setState({
                isPlaying: false,
                playImage: 'playcircle'
            });
        }       
    }

Any help will be appreciated.
Thanks in advance

@josev55

@ms88privat
Copy link

I got something similar some time ago. Try to add the key property to the image tag like <Image key={images[this.state.playImage].uri} ... />. This worked for me in this case #3471

@cosmith
Copy link
Contributor

cosmith commented Mar 9, 2016

@facebook-github-bot stack-overflow

@facebook-github-bot
Copy link
Contributor

Hey @josev55 and thanks for posting this! @cosmith tells me this issue looks like a question that would be best asked on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only. Will close this as this is really a question that should be asked on SO.

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Mar 9, 2016
@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants