diff --git a/App.tsx b/App.tsx index d0bbc1e..849ec62 100644 --- a/App.tsx +++ b/App.tsx @@ -5,8 +5,9 @@ import useColorScheme from './hooks/useColorScheme'; import Navigation from './navigation'; import {View} from "react-native"; import store from "./redux/store"; -import {Provider} from "react-redux"; - +import {Provider, useDispatch} from "react-redux"; +import {useEffect, useState} from "react"; +import {getTrendingID} from "./redux/actions/actionGetTrendingID"; export default function App() { const isLoadingComplete = useCachedResources(); diff --git a/assets/images/adaptive-icon.png b/assets/images/adaptive-icon.png index 03d6f6b..cf51fa3 100644 Binary files a/assets/images/adaptive-icon.png and b/assets/images/adaptive-icon.png differ diff --git a/assets/images/icon.png b/assets/images/icon.png index a0b1526..cd0ae33 100644 Binary files a/assets/images/icon.png and b/assets/images/icon.png differ diff --git a/assets/images/splash.png b/assets/images/splash.png index 0e89705..d003048 100644 Binary files a/assets/images/splash.png and b/assets/images/splash.png differ diff --git a/assets/images/splashscreen.png b/assets/images/splashscreen.png new file mode 100644 index 0000000..b7fa36b Binary files /dev/null and b/assets/images/splashscreen.png differ diff --git a/navigation/index.tsx b/navigation/index.tsx index 02c0b87..3bdfbbf 100644 --- a/navigation/index.tsx +++ b/navigation/index.tsx @@ -21,8 +21,47 @@ import FavoriteScreen from '../screens/FavoriteScreen'; import HomeScreen from '../screens/HomeScreen'; import {RootStackParamList, RootTabParamList, RootTabScreenProps} from '../types'; import LinkingConfiguration from './LinkingConfiguration'; +import {useCallback, useEffect, useState} from "react"; +import {useDispatch} from "react-redux"; +import {getTrendingID} from "../redux/actions/actionGetTrendingID"; +import * as SplashScreen from 'expo-splash-screen'; export default function Navigation({colorScheme}: { colorScheme: ColorSchemeName }) { + const [appIsReady, setAppIsReady] = useState(false); + const dispatch = useDispatch(); + useEffect(() => { + async function prepare() { + try { + const loadTrendingID = async () => { + // @ts-ignore + await dispatch(getTrendingID()); + }; + //console.log("test1:", trendingMovies); + loadTrendingID(); + } catch (e) { + console.warn(e); + } finally { + // Tell the application to render + setAppIsReady(true); + } + } + + prepare(); + }, []); + + const onLayoutRootView = useCallback(async () => { + if (appIsReady) { + // This tells the splash screen to hide immediately! If we call this after + // `setAppIsReady`, then we may see a blank screen while the app is + // loading its initial state and rendering its first pixels. So instead, + // we hide the splash screen once we know the root view has already + // performed layout. + await SplashScreen.hideAsync(); + } + }, [appIsReady]); + if (!appIsReady) { + return null; + } return ( ) { const [minutes, setMinutes] = useState(0); const [seconds, setSeconds] = useState(0); const [displayIndex, setdisplayIndex] = useState(0); - + var swiper = null; //console.log("liste [0]: ", trendingMovies[0]); @@ -98,7 +98,6 @@ export default function HomeScreen({navigation}: RootStackScreenProps<'Home'>) { const dispatch = useDispatch(); useEffect(() => { - // Créez une date avec la valeur actuelle const interval = setInterval(() => { const today = moment(); @@ -141,11 +140,19 @@ export default function HomeScreen({navigation}: RootStackScreenProps<'Home'>) { function addWatchLater(props: Movie) { dispatch(addMovieToWatchLater(props)); dispatch(removeMovieTrending(props)); + if (displayIndex == trendingMovies.length - 1) { + setdisplayIndex(0); + swiper.swipeLeft(); + } } function popFirstTrending(props: Movie) { dispatch(removeMovieTrending(props)); + if (displayIndex == trendingMovies.length - 1) { + setdisplayIndex(0); + swiper.swipeLeft(); + } } function formatTime(time: number) { @@ -172,9 +179,12 @@ export default function HomeScreen({navigation}: RootStackScreenProps<'Home'>) { source={require("../assets/images/background.png") } > - {trendingMovies[displayIndex] !== undefined && ( + + {trendingMovies.length !== 0 && ( + + ) { }} source={{ - uri: trendingMovies[displayIndex].poster_path, + uri: trendingMovies[displayIndex]?.poster_path, }} > @@ -204,36 +214,45 @@ export default function HomeScreen({navigation}: RootStackScreenProps<'Home'>) { { + swiper = rf + }} containerStyle={{zIndex: 20}} cards={trendingMovies} + loop={true} onSwipedLeft={(index) => { - if (index + 1 < trendingMovies.length) - setdisplayIndex(index + 1) - else + console.log(index) + if (index < trendingMovies.length - 1) { + + setdisplayIndex(index + 1); + + } else setdisplayIndex(0) } } onSwipedRight={(index) => { - if (index + 1 < trendingMovies.length) + if (index < trendingMovies.length) setdisplayIndex(index + 1) else setdisplayIndex(0) }} - renderCard={(card) => ( - )} + renderCard={(card) => + ( + ) + } /> { - addWatchLater(trendingMovies[0]); + addWatchLater(trendingMovies[displayIndex]); }}> @@ -243,7 +262,7 @@ export default function HomeScreen({navigation}: RootStackScreenProps<'Home'>) { { - popFirstTrending(trendingMovies[0]); + popFirstTrending(trendingMovies[displayIndex]); }}> ) { )} - {trendingMovies[displayIndex] === undefined && ( + {trendingMovies.length === 0 && ( Félicitations ! @@ -301,6 +320,7 @@ export default function HomeScreen({navigation}: RootStackScreenProps<'Home'>) { ) } + )