Last active
April 2, 2021 20:22
-
-
Save chanonroy/e7625dccb0f03ac9764d38cb6dbb070a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from "react" | |
| import { | |
| View, | |
| ScrollView, | |
| SafeAreaView, | |
| ImageBackground, | |
| Dimensions, | |
| } from "react-native" | |
| const ITEM_WIDTH = Dimensions.get("window").width | |
| const ITEM_HEIGHT = 200 | |
| const cards = [ | |
| { title: "Movie 1", posterUrl: require("./images/tenent.jpg") }, | |
| { title: "Movie 2", posterUrl: require("./images/1917.jpg") }, | |
| { title: "Movie 3", posterUrl: require("./images/spiderman.jpg") }, | |
| { title: "Movie 4", posterUrl: require("./images/mando.jpg") }, | |
| ] | |
| export default function SimpleCardCarousel() { | |
| return ( | |
| <SafeAreaView style={{ flex: 1, backgroundColor: "black" }}> | |
| <ScrollView | |
| horizontal={true} | |
| decelerationRate={"normal"} | |
| snapToInterval={ITEM_WIDTH} | |
| bounces={false} | |
| style={{ marginTop: 40, paddingHorizontal: 0 }} | |
| showsHorizontalScrollIndicator={false} | |
| scrollEventThrottle={12} | |
| > | |
| {cards.map((item, idx) => { | |
| return ( | |
| <View | |
| style={{ | |
| width: ITEM_WIDTH, | |
| height: ITEM_HEIGHT, | |
| }} | |
| > | |
| <ImageBackground | |
| source={item.posterUrl} | |
| style={{ | |
| flex: 1, | |
| resizeMode: "cover", | |
| justifyContent: "center", | |
| }} | |
| /> | |
| </View> | |
| ) | |
| })} | |
| </ScrollView> | |
| </SafeAreaView> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment