Created
October 19, 2018 13:41
-
-
Save obliviusm/62f1bbfb51f428a0f6212787709e0236 to your computer and use it in GitHub Desktop.
This file contains 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 from 'react' | |
import { View, Text, Dimensions } from 'react-native' | |
import Carousel from 'react-native-snap-carousel' | |
import PreviewSlide from './PreviewSlide' | |
import styles from './styles' | |
const convertViewportWidth = (percentage, viewportWidth) => { | |
const value = percentage * viewportWidth / 100 | |
return Math.round(value) | |
} | |
const getCarouselWidthParameters = () => { | |
const { width: viewportWidth } = Dimensions.get('window') | |
const slideWidth = convertViewportWidth(39.4, viewportWidth) | |
const itemHorizontalMargin = convertViewportWidth(2, viewportWidth) | |
const sliderWidth = viewportWidth | |
const itemWidth = slideWidth + itemHorizontalMargin * 2 | |
return { sliderWidth, itemWidth } | |
} | |
const renderVideoSlide = ({ item }) => { | |
return <PreviewSlide preview={item} /> | |
} | |
const VideoCarousel = ({ videoSlides }) => { | |
const { sliderWidth, itemWidth } = getCarouselWidthParameters() | |
return ( | |
<Carousel | |
data={videoSlides} | |
renderItem={renderVideoSlide} | |
sliderWidth={sliderWidth} | |
itemWidth={itemWidth} | |
slideStyle={{ width: itemWidth }} | |
activeSlideAlignment={'start'} | |
enableMomentum={true} | |
containerCustomStyle={styles.carousel} | |
inactiveSlideOpacity={1} | |
inactiveSlideScale={1} | |
/> | |
) | |
} | |
export default VideoCarousel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment