좌우로 스와이프 되는 영화 스와이프 스크린 화면을 개발
npm i react-native-web-swiper --save
웹에서도 사용할 수 있는 web-swiper를 활용
secret
파일에 따로 저장 후 사용이 파일은 .gitignore
을 통해 무시하도록 따로 설정
export const TMDB_KEY = "YOUR API KEY";
import React from "react";
import styled from "styled-components/native";
import { NativeStackScreenProps } from "@react-navigation/native-stack";
import Swiper from "react-native-web-swiper";
import { Dimensions } from "react-native";
import { TMDB_KEY } from "../secret";
const ScrollView = styled.ScrollView`
background-color: ${(props) => props.theme.mainBgColor};
`;
const View = styled.View`
flex: 1;
`;
const { height } = Dimensions.get("window");
const Movies: React.FC<NativeStackScreenProps<any, "Movies">> = ({
navigation: { navigate },
}) => {
const getNowPlaying = () => {
fetch(
`https://api.themoviedb.org/3/movie/now_playing?api_key=${TMDB_KEY}&language=en-US&page=1®ion=KR`
);
};
return (
<ScrollView>
<Swiper
loop
timeout={5}
controlsEnabled={false}
containerStyle={{ width: "100%", height: height / 4 }}
>
<View style={{ backgroundColor: "red" }}></View>
<View style={{ backgroundColor: "blue" }}></View>
<View style={{ backgroundColor: "red" }}></View>
<View style={{ backgroundColor: "blue" }}></View>
</Swiper>
</ScrollView>
);
};
export default Movies;
Dimensions.get("window")
: 윈도우의 높이를 가져옴loop
: 리스트가 끝나면 처음으로 루프timeout
: 자동으로 넘어가게 하고, 그 시간을 설정controlsEnabled
: 스와이퍼의 컨트롤러 정보들을 출력손가락으로 좌우 왔다갔다할 수도 있고, 자동으로 넘어가기도 하는 Swiper 구현 완료