From 6ff7c459e3d08ebdf6da6973ebe0410b5cab9c0a Mon Sep 17 00:00:00 2001 From: Alberto-Duarte Date: Thu, 11 May 2023 11:40:35 +0100 Subject: first commit --- screens/home.js | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 screens/home.js (limited to 'screens/home.js') diff --git a/screens/home.js b/screens/home.js new file mode 100644 index 0000000..184bbf9 --- /dev/null +++ b/screens/home.js @@ -0,0 +1,162 @@ +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; -- cgit v1.2.3-54-g00ecf