import {useCallback, useEffect, useState} from 'react'; import { ImageBackground, Platform, Pressable, SafeAreaView, ScrollView, Text, TextInput, View, } from 'react-native'; import tw from 'twrnc'; import {useDeviceContext} from 'twrnc'; import requests from '../lib/requests'; import PreviewCard from '../components/PreviewCard'; import Modal from './modal'; //ICONS import {TvIcon} from 'react-native-heroicons/outline'; import {MagnifyingGlassIcon} from 'react-native-heroicons/outline'; import {ChevronDownIcon} from 'react-native-heroicons/solid'; import {UserIcon} from 'react-native-heroicons/outline'; import ImageColors from 'react-native-image-colors'; import LinearGradient from 'react-native-linear-gradient'; const Home = ({navigation}) => { useDeviceContext(tw); const imgAssets = process.env.IMG_ASSETS; const [heroMovie, setHeroMovie] = useState(); const [heroMovieColor, setHeroMovieColor] = useState(); const [topRatedMovies, setTopRatedMovies] = useState(); const [isModalVisible, setModalVisible] = useState(false); const [modalContent, setModalContent] = useState(); const toggleModal = (movie) => { setModalVisible(!isModalVisible); setModalContent(movie); }; useEffect(() => { fetch(`https://api.themoviedb.org/3/movie/top_rated?api_key=f247ff737ec8062f3b5e027789eab748&language=en`) .then(res => res.json()) .then(data => { setHeroMovie(data.results[1]); setTopRatedMovies(data.results) }); }, []); useEffect(() => { const fetchColor = async () => { const data = await ImageColors.getColors( `https://image.tmdb.org/t/p/original${heroMovie?.poster_path}`, { fallback: '#000000', cache: true, key: 'unique_key', }, ).then(data => { if (Platform.OS === 'ios') { setHeroMovieColor(data.primary); } else { setHeroMovieColor(data.average); } }); } if (heroMovie?.poster_path != undefined) { fetchColor() .catch(e => { console.log(e) return e }); } }, [heroMovie]) return ( For Matias navigation.navigate('Profile')} style={tw`rounded bg-white/20 w-6 h-6 flex items-center justify-center`} > TV Shows Movies Categories {heroMovieColor !== undefined && ( )} Popular on Netflix { topRatedMovies?.map((movie, index) => ( toggleModal(movie)}> ))} {isModalVisible && ( )} ); }; export default Home;