0
I have a home screen with a carousel, where each item has a title and an image, however the image does not render at all, only the title. I’m not able to identify why this is happening, since the image URL is correct.
Home
import React, { Component } from "react";
import styles from "./styles";
import {
View,
Text,
Dimensions,
Image
} from "react-native";
import {
NavigationParams,
NavigationScreenProp,
NavigationState
} from 'react-navigation';
import Carousel from "react-native-snap-carousel";
import { ScrollView } from "react-native-gesture-handler";
const primeiroItem = 1;
const dados = [
{
title: 'Beautiful and dramatic Antelope Canyon',
subtitle: 'Lorem ipsum dolor sit amet et nuncat mergitur',
illustration: 'https://i.imgur.com/UYiroysl.jpg'
},
{
title: 'Earlier this morning, NYC',
subtitle: 'Lorem ipsum dolor sit amet',
illustration: 'https://i.imgur.com/UPrs1EWl.jpg'
},
{
title: 'White Pocket Sunset',
subtitle: 'Lorem ipsum dolor sit amet et nuncat ',
illustration: 'https://i.imgur.com/MABUbpDl.jpg'
},
]
const width = Dimensions.get("screen").width;
interface Props {
navigation: NavigationScreenProp<NavigationState, NavigationParams>;
}
export default class Home extends Component<Props> {
constructor(props: any) {
super(props);
this.state = {
slider1ActiveSlide: primeiroItem
};
}
_renderItem ({item, index}) {
return (
<View>
<Image
source={{ uri: item.illustration }}
/>
<Text>{ item.title }</Text>
</View>
);
}
render() {
return(
<ScrollView>
<Carousel
data={dados}
renderItem={this._renderItem}
sliderWidth={width}
itemWidth={width}
autoplay={true}
autoplayDelay={500}
autoplayInterval={3000}
firstItem={primeiroItem}
onSnapToItem={(index) => this.setState({ slider1ActiveSlide: index }) }
/>
</ScrollView>
)
}
I was able to fix it, thank you! I didn’t know that width and heigth were required to render images in React Native
– Juliana Marques