Skip to content

Commit d498d45

Browse files
philipphenkelkenwheeler
authored andcommitted
Fix transition direction of slides with string based hashes (#339)
Use the manager’s slide reference to properly look up the route’s slide index. Update test snapshot of manager and markdown slide.
1 parent 1d3f31d commit d498d45

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/components/__snapshots__/manager.test.js.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ exports[`<Manager /> should render correctly. 1`] = `
110110
lastSlideIndex={0}
111111
print={false}
112112
slideIndex={0}
113+
slideReference={
114+
Array [
115+
Object {
116+
"id": 0,
117+
"rootIndex": 0,
118+
},
119+
Object {
120+
"id": 1,
121+
"rootIndex": 1,
122+
},
123+
]
124+
}
113125
transition={
114126
Array [
115127
"zoom",
@@ -655,6 +667,24 @@ exports[`<Manager /> should render with slideset slides 1`] = `
655667
lastSlideIndex={1}
656668
print={false}
657669
slideIndex={1}
670+
slideReference={
671+
Array [
672+
Object {
673+
"id": 0,
674+
"rootIndex": 0,
675+
},
676+
Object {
677+
"id": 1,
678+
"rootIndex": 1,
679+
"setIndex": 0,
680+
},
681+
Object {
682+
"id": 2,
683+
"rootIndex": 1,
684+
"setIndex": 1,
685+
},
686+
]
687+
}
658688
transition={Array []}
659689
transitionDuration={500}
660690
>

src/components/manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ export default class Manager extends Component {
462462
transitionDuration: (slide.props.transition || {}).transitionDuration
463463
? slide.props.transitionDuration
464464
: this.props.transitionDuration,
465+
slideReference: this.state.slideReference
465466
});
466467
}
467468
render() {

src/components/transitionable.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*eslint new-cap:0, max-statements:0*/
22
import React, { cloneElement } from 'react';
33
import { VictoryAnimation } from 'victory-core';
4+
import findIndex from 'lodash/findIndex';
45

56
/**
67
* Decorator for adding Spectacle transition support
@@ -36,8 +37,8 @@ const Transitionable = function (target) {
3637

3738
transitionDirection() {
3839
const { slideIndex, lastSlideIndex } = this.props;
39-
const slide = this.context.store.getState().route.slide || 0;
40-
return this.state.reverse ? slideIndex > slide : slideIndex > lastSlideIndex;
40+
const routeSlideIndex = this._getRouteSlideIndex();
41+
return this.state.reverse ? slideIndex > routeSlideIndex : slideIndex > lastSlideIndex;
4142
},
4243

4344
getTransitionStyles() {
@@ -68,7 +69,16 @@ const Transitionable = function (target) {
6869
}
6970

7071
return { ...styles, transform: transformValue };
71-
}
72+
},
73+
74+
_getRouteSlideIndex() {
75+
const { slideReference } = this.props;
76+
const slide = this.context.store.getState().route.slide;
77+
const slideIndex = findIndex(slideReference, reference => {
78+
return slide === String(reference.id);
79+
});
80+
return Math.max(0, slideIndex);
81+
},
7282
};
7383

7484
Object.assign(target.prototype, transitionable);

0 commit comments

Comments
 (0)