Skip to content

Commit 5b68c09

Browse files
MathEman-1ebrillhart
authored andcommitted
Feature/autoplay toggle on start (#637)
* Added autoplay toggle on key combination if enabled * Added autoplayOnStart as Deck tag/prop * Fixed _toggleAutoplaying & linting issue * Updated jest snapshot * Prettier fix * Added index.d.ts definition
1 parent 21ec468 commit 5b68c09

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ You can toggle the presenter or overview mode by pressing respectively `alt+p` a
278278
| Alt/Option + O | Toggle Overview Mode |
279279
| Alt/Option + P | Toggle Presenter Mode |
280280
| Alt/Option + T | Toggle Timer in Presenter Mode |
281-
| Alt/Option + A | Start autoplay (if enabled) |
281+
| Alt/Option + A | Toggle autoplay (if enabled) |
282282
| Alt/Option + F | Toggle Fullscreen Mode |
283283

284284
<a name="fullscreen"></a>
@@ -476,6 +476,7 @@ The Deck tag is the root level tag for your presentation. It supports the follow
476476
| autoplay | PropTypes.bool | Automatically advance slides. | `false` |
477477
| autoplayDuration | PropTypes.number | Accepts integer value in milliseconds for global autoplay duration. | `7000` |
478478
| autoplayLoop | PropTypes.bool | Keep slides in loop. | `true` |
479+
| autoplayOnStart | PropTypes.bool | Start presentation with autoplay on/not paused (if autoplay is enabled). | `true` |
479480
| controls | PropTypes.bool | Show control arrows when not in fullscreen. | `true` |
480481
| contentHeight | PropTypes.numbers | Baseline content area height. | `700px` |
481482
| contentWidth | PropTypes.numbers | Baseline content area width. | `1000px` |

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ declare module 'spectacle' {
157157
autoplay?: boolean;
158158
autoplayDuration?: number;
159159
autoplayLoop?: boolean;
160+
autoplayOnStart?: boolean;
160161
controls?: boolean;
161162
globalStyles?: boolean;
162163
history?: any; // Needs a type, see https://github.com/ReactTraining/history

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports[`<Manager /> should render correctly. 1`] = `
1414
autoplay={false}
1515
autoplayDuration={7000}
1616
autoplayLoop={true}
17+
autoplayOnStart={true}
1718
contentHeight={700}
1819
contentWidth={1000}
1920
controls={true}
@@ -354,6 +355,7 @@ exports[`<Manager /> should render fullscreen button dependant on prop 1`] = `
354355
autoplay={false}
355356
autoplayDuration={7000}
356357
autoplayLoop={true}
358+
autoplayOnStart={true}
357359
contentHeight={700}
358360
contentWidth={1000}
359361
controls={true}
@@ -666,6 +668,7 @@ exports[`<Manager /> should render the export configuration when specified. 1`]
666668
autoplay={false}
667669
autoplayDuration={7000}
668670
autoplayLoop={true}
671+
autoplayOnStart={true}
669672
contentHeight={700}
670673
contentWidth={1000}
671674
controls={true}
@@ -800,6 +803,7 @@ exports[`<Manager /> should render the overview configuration when specified. 1`
800803
autoplay={false}
801804
autoplayDuration={7000}
802805
autoplayLoop={true}
806+
autoplayOnStart={true}
803807
contentHeight={700}
804808
contentWidth={1000}
805809
controls={true}
@@ -960,6 +964,7 @@ exports[`<Manager /> should render with slideset slides 1`] = `
960964
autoplay={false}
961965
autoplayDuration={7000}
962966
autoplayLoop={true}
967+
autoplayOnStart={true}
963968
contentHeight={700}
964969
contentWidth={1000}
965970
controls={true}

src/components/deck.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class Deck extends Component {
2626
autoplay: PropTypes.bool,
2727
autoplayDuration: PropTypes.number,
2828
autoplayLoop: PropTypes.bool,
29+
autoplayOnStart: PropTypes.bool,
2930
children: PropTypes.node,
3031
controls: PropTypes.bool,
3132
globalStyles: PropTypes.bool,

src/components/manager.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class Manager extends Component {
103103
autoplay: PropTypes.bool,
104104
autoplayDuration: PropTypes.number,
105105
autoplayLoop: PropTypes.bool,
106+
autoplayOnStart: PropTypes.bool,
106107
children: PropTypes.node,
107108
contentHeight: PropTypes.number,
108109
contentWidth: PropTypes.number,
@@ -139,6 +140,7 @@ export class Manager extends Component {
139140
autoplay: false,
140141
autoplayDuration: 7000,
141142
autoplayLoop: true,
143+
autoplayOnStart: true,
142144
contentWidth: 1000,
143145
contentHeight: 700,
144146
disableKeyboardControls: false,
@@ -167,7 +169,7 @@ export class Manager extends Component {
167169
slideReference: [],
168170
fullscreen: window.innerHeight === screen.height,
169171
mobile: window.innerWidth < props.contentWidth,
170-
autoplaying: props.autoplay
172+
autoplaying: props.autoplay ? props.autoplayOnStart : false
171173
};
172174

173175
this.viewedIndexes = new Set();
@@ -188,11 +190,14 @@ export class Manager extends Component {
188190

189191
componentDidMount() {
190192
const slideIndex = this._getSlideIndex();
193+
const autoplayOnStart = this.props.autoplay
194+
? this.props.autoplayOnStart
195+
: false;
191196
this.setState({
192197
lastSlideIndex: slideIndex
193198
});
194199
this._attachEvents();
195-
if (this.props.autoplay) {
200+
if (autoplayOnStart) {
196201
this._startAutoplay();
197202
}
198203
}
@@ -249,6 +254,13 @@ export class Manager extends Component {
249254
this.setState({ autoplaying: false });
250255
clearInterval(this.autoplayInterval);
251256
}
257+
_toggleAutoplaying() {
258+
if (this.state.autoplaying) {
259+
this._stopAutoplay();
260+
} else {
261+
this._startAutoplay();
262+
}
263+
}
252264
_handleEvent(e) {
253265
// eslint-disable-line complexity
254266
const event = window.event ? window.event : e;
@@ -297,7 +309,7 @@ export class Manager extends Component {
297309
!event.metaKey &&
298310
this.props.autoplay
299311
) {
300-
this._startAutoplay();
312+
this._toggleAutoplaying();
301313
} else if (
302314
event.altKey &&
303315
event.keyCode === 70 && // 'f'

0 commit comments

Comments
 (0)