Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

44
Vistas
How do I pass a prop that contains the image location to image source when rendering many images in a flatlist?

My code below accepts inputPhotoLocation as a prop. inputPhotoLocation contains a list of image source locations (which have been retrieved from a file containing a list). I need a way to pass these to my image source. I have been able to pass the locations directly in the text box with success.

function SelectionBoxComponent({inputPhotoLocation, inputText, onPress}) {
    return (

        <TouchableWithoutFeedback onPress={onPress}>
            <View style={styles.box}>
                <View style={styles.circularPhoto}>
                    <Image style={{height:"100%", width:"100%", borderRadius:70,
                        borderWidth:0, source={require(inputPhotoLocation)}}} ></Image> {/* Here I need to insert the list items */}
                </View>

                <AppText style={styles.textStyle} onPress={console.log(inputText)} >
                    {inputText}</AppText>

            </View>
        </TouchableWithoutFeedback>

My inputPhotoLocation prop contains this:

./assets/GroupImages/football.jpg

../assets/GroupImages/valley.jpg

../assets/GroupImages/usa.jpg

../assets/GroupImages/playstation.jpg

../assets/GroupImages/pc.jpg

I am able to pass these locations as text outputs successfully. However, I can't figure out how to pass these in the image source.

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

      <Image
        style={{
          height: '100%',
          width: '100%',
          borderRadius: 70,
          borderWidth: 0,
          {/* The source prop is not a style prop */}
          source={require(inputPhotoLocation)
        }}></Image>



      <Image
        {/* The source prop is Image prop */}
        source={require(inputPhotoLocation)
        style={{
          height: '100%',
          width: '100%',
          borderRadius: 70,
          borderWidth: 0
        }}></Image>
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos