fetch, Swiper, ActivityIndicator, Dimensions, BlurView, Scrollview

김종민·2022년 4월 7일
0

React-Native(1. Movie)

목록 보기
10/20
import styled from 'styled-components/native'
import Swiper from 'react-native-web-swiper'
import { NativeStackScreenProps } from '@react-navigation/native-stack'
import { ActivityIndicator, Dimensions } from 'react-native'
import { makeImgPath } from '../util'
import { BlurView } from 'expo-blur'

const API_KEY = '86d6efd228f2052ac88a791925717fc9'

const Container = styled.ScrollView``

const View = styled.View`
  flex: 1;
`
const Loader = styled.View`
  flex: 1;
  justify-content: center;
  align-items: center;
`

const BgImg = styled.Image`
  width: 100%;
  height: 100%;
  position: absolute;
`
const Title = styled.Text`
  font-size: 25;
  color: white;
`

const { height: SCREEN_HEIGHT } = Dimensions.get('window')

const Movies: React.FC<NativeStackScreenProps<any, 'Movies'>> = () => {
  const [loading, setLoading] = useState(true)
  const [nowPlaying, setNowPlaying] = useState([])
  const getNowPlaying = async () => {
    const { results } = await (
      await fetch(
        `https://api.themoviedb.org/3/movie/now_playing?api_key=${API_KEY}&language=en-US&page=1&region=KR`
      )
    ).json()
    setNowPlaying(results)
    setLoading(false)
  }

  useEffect(() => {
    getNowPlaying()
  })
  return loading ? (
    <Loader>
      <ActivityIndicator color="black" size="large" />
    </Loader>
  ) : (
    <Container>
      <Swiper
        loop
        timeout={2}
        controlsEnabled={false}
        containerStyle={{ width: '100%', height: SCREEN_HEIGHT / 4 }}
      >
        {nowPlaying.map((movie) => (
          <View
            key={movie.id}
            style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
          >
            <BgImg source={{ uri: makeImgPath(movie.backdrop_path) }} />
            <BlurView>
              <Title>{movie.original_title}</Title>
            </BlurView>
          </View>
        ))}
      </Swiper>
    </Container>
  )
}

export default Movies

fetch,
Swiper,
ActivityIndicator,
Dimensions,
BlurView,
Scrollview
Movies 함수의 type
다 확인해볼것!!!!!

profile
코딩하는초딩쌤

1개의 댓글

comment-user-thumbnail
2024년 2월 13일

Enveloped in the soft glow of the screen, I surrendered to the enchanting allure of cinematic storytelling, eagerly anticipating the thrilling adventure that lay ahead. Tonight's film invited me into a world of imagination and wonder, promising an unforgettable escapade. With each unfolding frame, I was transported to new realms https://kinogo-go.online/ and dimensions, where reality seamlessly merged with fantasy. From tender moments of love to heart-pounding action sequences, I was captivated by the sheer brilliance of cinematic artistry. In those transcendent moments, I felt an unexplainable connection to the characters and their narrative, as if their struggles mirrored my own.

답글 달기