Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
RN- How to show loader icon on screen until image is loaded?

I'm new to React native. Pictures change when the previous and next buttons are pressed in the application. But it waits for a while until the pictures are loaded onto the screen. Because the images are coming from firebase storage. When the button is pressed, I want a loading icon to appear until the images are loaded. I don't know how to use ActivityIndicator in this situation. Can anybody help me for that?

Application image:

enter image description here

Codes:

import React, { useState } from 'react'
import { Image, Text, TouchableOpacity, View } from 'react-native'
import { StyleSheet } from 'react-native'


const data = [
    { url: "https://firebasestorage.googleapis.com/v0/b/asdsa-69cc0.appspot.com/o/1.jpg?alt=media&token=52de8fce-553d-436d-839e-cc3ee0ec29eb" },
    { url: "https://firebasestorage.googleapis.com/v0/b/asdsa-69cc0.appspot.com/o/2.jpg?alt=media&token=0fa85f40-f134-4010-b575-63c1c82e9c81" }
]

const WordPage = () => {

    const [picture, setPicture] = useState(data[0].url)

    const nextWord = () => {
        setPicture(data[1].url)
    }

    const previousWord = () => {
        setPicture(data[0].url)
    }

    return (
        <View style={styles.container}>
            <Image source={{ uri: picture }}
                style={styles.image}
            />
            <View style={styles.change}>
                <TouchableOpacity onPress={previousWord}>
                    <Text>
                        Previous
                    </Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={nextWord}>
                    <Text>
                        Next
                    </Text>
                </TouchableOpacity>
            </View>
        </View>
    )
}

export default WordPage

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    image: {
        height: 300,
        width: 300,
        alignSelf: 'center',
        borderRadius: 10,
        resizeMode: 'contain',
        marginTop: 20
    },
    change: {
        flexDirection: 'row',
        marginHorizontal: 10,
        marginTop: 20,
        alignItems: 'center',
        justifyContent: 'space-between'
    }
});

I could not apply what is written on this page : How do I conditionally render a spinner while waiting for a new image to load?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

while loading images from a URL we can make use of the props available for Image components. Props like onLoadStart can be used to set a state variable to show an ActivityIndicator while image loading is started and props like onLoad or onLoadEnd can be used to change the value of the state variable to hide the ActivityIndicator once the loading is done.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda