Skip to content
This repository has been archived by the owner on Apr 1, 2021. It is now read-only.

Commit

Permalink
Carousel v2 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobdn-sfeir committed Jan 8, 2018
1 parent aedbf07 commit e0383c3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dev/dev.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class CarouselV2Wrapper extends React.Component {
itemsVisiblesCount={3}
loop={loop}
onEnter={this.onEnter}
preloadItemsCount={5}
preloadItemsCount={3}
focusedClassName={'focuseditemlol'}
nestedFocusedClassName={'focuseditemlolilol'}
wrapperWidth={600}
Expand Down
13 changes: 8 additions & 5 deletions src/components/carouselv2/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Carousel extends Component {
};
}

renderItems(carouselId, iFocused, itemsVisiblesCount, children, direction, itemStyles, preloadItemsCount, scrollableTranslateY, wrapperHeight) {
renderItems(carouselId, iFocused, itemsVisiblesCount, children, direction, itemStyles, preloadItemsCount, scrollableTranslateX, scrollableTranslateY, wrapperHeight) {
const { verticalChildItemWrapper } = this.props;
if (direction === CAROUSEL_DIRECTIONS.verticalBidirectional) {
const maxItemsVisible = iFocused + itemsVisiblesCount + preloadItemsCount;
Expand All @@ -128,7 +128,7 @@ class Carousel extends Component {
const maxNestedItemsVisible = nestedIFocused + itemsVisiblesCount + preloadItemsCount;
const minNestedItemsVisible = nestedIFocused - itemsVisiblesCount - preloadItemsCount;

if (!isItemVisible) {
if (!isItemVisible && iIndex < maxItemsVisible) {
const height = getItemOffsetHeight(carouselId, iIndex);
const width = getItemOffsetWidth(carouselId, iIndex);
return (
Expand All @@ -138,10 +138,12 @@ class Carousel extends Component {
</div>
)
}

return isItemVisible && (
<CarouselItem
carouselId={carouselId}
direction={direction}
hasNestedItems
key={`item_${iIndex}`}
itemIndex={iIndex}
itemStyles={itemStyles}
Expand All @@ -158,13 +160,13 @@ class Carousel extends Component {
carouselId={`${carouselId}_${iIndex}`}
direction={CAROUSEL_DIRECTIONS.horizontal}
nested
scrollableTranslateX={0}
scrollableTranslateY={0}
scrollableTranslateX={scrollableTranslateX}
scrollableTranslateY={scrollableTranslateY}
>
{nestedChild.props.children.map((nestedChildItem, iNestedItem) => {
const isItemVisible = iNestedItem < maxNestedItemsVisible && iNestedItem > minNestedItemsVisible

if (!isItemVisible) {
if (!isItemVisible && iNestedItem < maxNestedItemsVisible) {
const width = getNestedItemOffsetWidth(carouselId, iIndex, iNestedItem);
return (
<div key={`spacer_${iIndex}_${iNested}_${iNestedItem}`} style={{ display: 'inline-block' }}>
Expand Down Expand Up @@ -324,6 +326,7 @@ class Carousel extends Component {
direction,
itemStyles,
preloadItemsCount,
scrollableTranslateX,
scrollableTranslateY,
wrapperHeight
)
Expand Down
8 changes: 6 additions & 2 deletions src/components/carouselv2/CarouselItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class CarouselItem extends Component {
}
}

shouldComponentUpdate(){
return this.props.hasNestedItems ? true : false;
}

render() {
const {
direction,
Expand All @@ -29,7 +33,7 @@ class CarouselItem extends Component {
height: `${itemHeight}px`,
display: direction === CAROUSEL_DIRECTIONS.horizontal ? 'inline-block' : 'block'
};

return (
<div ref={(el) => { this.el = el }} style={itemWrapperStyles}>
<div style={itemStyles}>
Expand All @@ -40,4 +44,4 @@ class CarouselItem extends Component {
}
}

export default CarouselItem;
export default CarouselItem;
6 changes: 3 additions & 3 deletions src/components/carouselv2/CarouselScrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CarouselScrollable extends React.PureComponent {
}
}

getVerticalScrollableStyles(scrollableTranslateY, scrollableHeight) {
getVerticalScrollableStyles(scrollableHeight) {
return {
width: '100%',
height: scrollableHeight,
Expand All @@ -48,8 +48,8 @@ class CarouselScrollable extends React.PureComponent {
scrollableWidth
} = this.props;

const scrollableStyles = direction === CAROUSEL_DIRECTIONS.horizontal ? this.getHorizontalScrollableStyles() : this.getVerticalScrollableStyles(scrollableTranslateY, scrollableHeight),
scrollable2Styles = this.getHorizontalScrollableStyles(scrollable2TranslateX, scrollableWidth);
const scrollableStyles = direction === CAROUSEL_DIRECTIONS.horizontal ? this.getHorizontalScrollableStyles() : this.getVerticalScrollableStyles(scrollableHeight),
scrollable2Styles = this.getHorizontalScrollableStyles();

return (
<div className="keys-carousel-scrollable" ref={(el) => { this.el = el }} style={scrollableStyles} >
Expand Down

0 comments on commit e0383c3

Please sign in to comment.