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

Image not loading in Typescript #97

Open
gitsjhare opened this issue Aug 20, 2022 · 0 comments
Open

Image not loading in Typescript #97

gitsjhare opened this issue Aug 20, 2022 · 0 comments

Comments

@gitsjhare
Copy link

gitsjhare commented Aug 20, 2022

Here is my Code in Typescript, where I created Image array with various links (URL) but non of them is loading while the same code when we have in JS all the images are loaded. let me know what I am missing for TS.

import React, {useRef, useState, useEffect} from 'react';
import Carousel, {ParallaxImage} from 'react-native-snap-carousel';
import {
  View,
  Text,
  Dimensions,
  StyleSheet,
  TouchableOpacity,
  Platform,
} from 'react-native';



type ImageSource={
    title:string,
    subtitle: string,
    illustration: string
}

const Images : ImageSource[] =[ {
    title: 'Beautiful and dramatic Antelope Canyon',
    subtitle: 'Lorem ipsum dolor sit amet et nuncat mergitur',
    illustration: './assets/images/first.jpg',
  },
  {
    title: 'Earlier this morning, NYC',
    subtitle: 'Lorem ipsum dolor sit amet',
    illustration: '../assets/images/second.jpg',
  },
  {
    title: 'White Pocket Sunset',
    subtitle: 'Lorem ipsum dolor sit amet et nuncat ',
    illustration: '../assets/images/Third.jpg',
  },
  {
    title: 'Acrocorinth, Greece',
    subtitle: 'Lorem ipsum dolor sit amet et nuncat mergitur',
    illustration: '../assets/images/fourth.jpg',
  },
  {
    title: 'The lone tree, majestic landscape of New Zealand',
    subtitle: 'Lorem ipsum dolor sit amet',
    illustration: 'https://i.imgur.com/2nCt3Sbl.jpg',
  },];

const {width: screenWidth} = Dimensions.get('window');

export const MyCarouselTsx=()=>{
    const [entries, setEntries] = useState<ImageSource[]>([]);
    const carouselRef =useRef(null);

    const goForward = () => {
        carouselRef.current.snapToNext();
      };
      
    useEffect(() => {
        setEntries(Images);
      }, []);
      
      /* const renderItem = ({item, index}, parallaxProps) => {
        return (
          <Item style={styles.item} title={undefined}>
            <ParallaxImage
              source={{uri: item.illustration}}
              containerStyle={styles.imageContainer}
              style={styles.image}
              parallaxFactor={0.4}
              {...parallaxProps}
            />
            <Text style={styles.title} numberOfLines={2}>
              {item.title}
            </Text>
          </Item>
        );
      }; */

      const _renderItem=({item,index, parallaxProps} : any)=>{
        return (
        
<View style={styles.item}>
{ console.log(item.illustration) }
  <ParallaxImage
              source={{ uri : item.illustration}}
              containerStyle={styles.imageContainer}
              style={styles.image}
              parallaxFactor={0.4}
              {...parallaxProps}
            />
            <Text style={styles.title} numberOfLines={2}>
              {item.title}
            </Text>
</View>
        );
      }
      return (
        <View style={styles.container}>
          <TouchableOpacity onPress={goForward}>
            <Text>go to next slide</Text>
          </TouchableOpacity>
          <Carousel
           
            sliderWidth={screenWidth}
            sliderHeight={screenWidth}
            itemWidth={screenWidth - 60}
            data={entries}
            renderItem={_renderItem}
            hasParallaxImages={true}
          />
        </View>
      );
}

const styles = StyleSheet.create({
    title : {

    },
    container: {
      flex: 1,
    },
    item: {
      width: screenWidth - 60,
      height: screenWidth - 60,
    },
    imageContainer: {
      flex: 1,
      marginBottom: Platform.select({ios: 0, android: 1}), // Prevent a random Android rendering issue
      backgroundColor: 'white',
      borderRadius: 8,
      display: "flex",
      zIndex: 10
    },
    image: {
      ...StyleSheet.absoluteFillObject,
      resizeMode: 'cover',
    },
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant