Skip to content

Commit

Permalink
Merge pull request #111 from sag1v/next
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
sag1v authored Nov 15, 2020
2 parents b8d5392 + 7262e18 commit ac7f254
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-elastic-carousel",
"version": "0.9.4",
"version": "0.9.5-beta.2",
"description": "A flexible and responsive carousel component for react",
"author": "sag1v (Sagiv Ben Giat)",
"license": "MIT",
Expand Down
45 changes: 31 additions & 14 deletions src/react-elastic-carousel/components/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Pagination } from "./Pagination";
class Carousel extends React.Component {
state = {
rootHeight: 0,
rootWidth: 0,
childWidth: 0,
childHeight: 0,
sliderPosition: 0,
Expand Down Expand Up @@ -97,10 +96,20 @@ class Carousel extends React.Component {
this.ro = new ResizeObserver((entries, observer) => {
for (const entry of entries) {
if (entry.target === this.sliderContainer) {
this.onContainerResize(entry);
// we are using rAF because it fixes the infinite refresh with gatsby (ssr?).
// TBH, I'm not sure i fully understand why.
// see https://github.com/sag1v/react-elastic-carousel/issues/107
window.requestAnimationFrame(() => {
this.onContainerResize(entry);
});
}
if (entry.target === this.slider) {
this.onSliderResize(entry);
// we are using rAF because it fixes the infinite refresh with gatsby (ssr?).
// TBH, I'm not sure i fully understand why
// see https://github.com/sag1v/react-elastic-carousel/issues/107
window.requestAnimationFrame(() => {
this.onSliderResize(entry);
});
}
}
});
Expand Down Expand Up @@ -156,8 +165,8 @@ class Carousel extends React.Component {
.find(bp => bp.width <= sliderContainerWidth);
if (!currentBreakPoint) {
/* in case we don't have a lower width than sliderContainerWidth
* this mostly happens in initilization when sliderContainerWidth is 0
*/
* this mostly happens in initilization when sliderContainerWidth is 0
*/
currentBreakPoint = breakPoints[0];
}
}
Expand Down Expand Up @@ -232,8 +241,8 @@ class Carousel extends React.Component {
} = this.getDerivedPropsFromBreakPoint();

/* based on slider container's width, get num of items to show
* and calculate child's width (and update it in state)
*/
* and calculate child's width (and update it in state)
*/
const childrenLength = Children.toArray(children).length;
let childWidth = 0;
if (verticalMode) {
Expand All @@ -250,10 +259,10 @@ class Carousel extends React.Component {
state => ({ childWidth }),
() => {
/* Based on all of the above new data:
* update slider position
* get the new current breakpoint
* pass the current breakpoint to the consumer's callback
*/
* update slider position
* get the new current breakpoint
* pass the current breakpoint to the consumer's callback
*/
this.updateSliderPosition();
const currentBreakPoint = this.getDerivedPropsFromBreakPoint();
onResize(currentBreakPoint);
Expand Down Expand Up @@ -381,10 +390,18 @@ class Carousel extends React.Component {
// bail out of state update
return;
}
let swipedSliderPosition;
if (horizontalSwipe) {
if (isRTL) {
swipedSliderPosition = sliderPosition + deltaX;
} else {
swipedSliderPosition = sliderPosition - deltaX;
}
} else {
swipedSliderPosition = sliderPosition - deltaY;
}
return {
swipedSliderPosition: horizontalSwipe
? sliderPosition - deltaX
: sliderPosition - deltaY,
swipedSliderPosition,
isSwiping: true,
transitioning: true
};
Expand Down

0 comments on commit ac7f254

Please sign in to comment.