Skip to content

Commit 2c20c8d

Browse files
committed
spiking full screen container
1 parent 93a95ea commit 2c20c8d

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

app/Player.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { Component } from 'react';
44
import { Provider } from 'react-redux';
55

66
import configureStore from './store/configurePlayerStore';
7+
import Fullscreen from './containers/Fullscreen.jsx';
78
import PlaybackControls from './containers/PlaybackControls.jsx';
89
import mapStoreToPlayer from './store/mapStoreToPlayer';
910

@@ -16,12 +17,12 @@ class Player extends Component {
1617

1718
render() {
1819
return (<Provider store={store}>
19-
<div>
20+
<Fullscreen>
2021
<video ref="video">
2122
<source src={this.props.src} />
2223
</video>
2324
<PlaybackControls />
24-
</div>
25+
</Fullscreen>
2526
</Provider>);
2627
}
2728
}

app/containers/Fullscreen.jsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
import React, { Component } from 'react';
4+
5+
import { bindActionCreators } from 'redux';
6+
import { connect } from 'react-redux';
7+
8+
import { setFullscreen } from '../actions/setFullscreen';
9+
10+
export class Fullscreen extends Component {
11+
_getFullscreenClassName() {
12+
const className = this.props.fullscreen ? 'is-fullscreen' : 'is-embedded';
13+
return `fullscreen ${className}`;
14+
}
15+
16+
_fullscreenChangeListener() {
17+
const fullscreenElement = document.webkitFullscreenElement;
18+
19+
if (!fullscreenElement) {
20+
this.props.setFullscreenAction(false);
21+
}
22+
}
23+
24+
componentWillMount() {
25+
document.addEventListener('webkitfullscreenchange', this._fullscreenChangeListener.bind(this));
26+
}
27+
28+
componentWillUnmount() {
29+
document.removeEventListener('webkitfullscreenchange', this._fullscreenChangeListener);
30+
}
31+
32+
componentWillUpdate() {
33+
if (this.props.fullscreen) document.webkitCancelFullScreen();
34+
else this.refs.fullscreen.webkitRequestFullscreen();
35+
}
36+
37+
render() {
38+
return (
39+
<div className={this._getFullscreenClassName()} ref="fullscreen">{this.props.children}</div>
40+
);
41+
}
42+
}
43+
44+
Fullscreen.propTypes = {
45+
fullscreen: React.PropTypes.bool,
46+
setFullscreenAction: React.PropTypes.func,
47+
children: React.PropTypes.arrayOf(React.PropTypes.element)
48+
};
49+
50+
function mapStateToProps(state) {
51+
return {
52+
fullscreen: state.playback.fullscreen,
53+
fullscreenSource: state.playback.fullscreenSource
54+
};
55+
}
56+
57+
function mapDispatchToProps(dispatch) {
58+
return {
59+
setFullscreenAction: bindActionCreators(setFullscreen, dispatch)
60+
};
61+
}
62+
63+
export default connect(
64+
mapStateToProps,
65+
mapDispatchToProps
66+
)(Fullscreen);

test/containers/Fullscreen.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
import React from 'react';
4+
import assert from 'assert';
5+
import { mount } from 'enzyme';
6+
import sinon from 'sinon';
7+
8+
import { Fullscreen } from '../../app/containers/Fullscreen.jsx';
9+
10+
describe('<Fullscreen />', () => {
11+
it('renders the children that are passed in with the component');
12+
13+
describe('class names', () => {
14+
it('adds is-fullscreen when the component is fullscreen');
15+
it('adds is-embedded when the component is not fullscreen');
16+
});
17+
18+
describe('event listeners', () => {
19+
it('adds the fullscreenchange event when the component is rendered');
20+
it('remove the fullscreenchange event when the component is removed');
21+
});
22+
});

test/containers/PlaybackControls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('<PlaybackControls />', () => {
6262
});
6363
});
6464

65-
describe.only('fullscreen <Button />', () => {
65+
describe('fullscreen <Button />', () => {
6666
it('sets "enter fullscreen" as the button text', () => {
6767
const wrapper = mount(<PlaybackControls isPlaying={true} fullscreen={false} />);
6868

0 commit comments

Comments
 (0)