import React from 'react' import { View, ScrollView, Text, StyleSheet, Image, ImageBackground, TouchableOpacity } from 'react-native' import Theme from '../theme.style.js'; import Board from './board.js'; import Promo from './promo.js'; export const Carousel = (props) => { const { items, style } = props; const itemsPerInterval = props.itemsPerInterval === undefined ? 1 : props.itemsPerInterval; const [interval, setInterval] = React.useState(1); const [intervals, setIntervals] = React.useState(1); const [width, setWidth] = React.useState(0); const init = (width) => { // initialise width setWidth(width); // initialise total intervals const totalItems = items.length; setIntervals(Math.ceil(totalItems / itemsPerInterval)); } const getInterval = (offset) => { for (let i = 1; i <= intervals; i++) { if (offset < (width / intervals) * i) { return i; } if (i == intervals) { return i; } } } let bullets = []; for (let i = 1; i <= intervals; i++) { if(props.type == "board"){ bullets.push( ); }else if(props.type == "promo"){ bullets.push( ); } } return ( {props.type == "board" ? init(w)} onScroll={data => { setWidth(data.nativeEvent.contentSize.width); setInterval(getInterval(data.nativeEvent.contentOffset.x)); }} items={items} onPress={props.onPress} bullets={bullets} /> : init(w)} onScroll={data => { setWidth(data.nativeEvent.contentSize.width); setInterval(getInterval(data.nativeEvent.contentOffset.x)); }} items={items} onPress={props.onPress} bullets={bullets} /> } ) } const styles = StyleSheet.create({ statsHead: { paddingTop: 10, paddingHorizontal: 12, }, container: { height: '100%', width: '100%', backgroundColor: '#fbfbfb', shadowColor: '#fcfcfc', shadowOpacity: 1, shadowOffset: { width: 0, height: 5 }, }, scrollView: { display: 'flex', flexDirection: 'row', overflow: 'hidden', width: '100%', height: '100%' }, bullets: { position: 'absolute', bottom: 0, display: 'flex', justifyContent: 'flex-start', flexDirection: 'row', paddingHorizontal: 10, paddingTop: 5, }, button: { position: 'absolute', bottom: 20, right: 35, display: 'flex', justifyContent: 'flex-end', flexDirection: 'row', paddingHorizontal: 10, paddingTop: 5, }, bullet: { paddingHorizontal: 3, alignSelf: 'center', left: 20 }, bullet2: { paddingHorizontal: 5, alignSelf: 'center', } }); export default Carousel; // switch (style) { // case 'stats': // return ( // // ); // default: // return ( // // ); // }