Allow video to be expanded into lightbox

This commit is contained in:
blackle 2017-04-13 09:04:18 -04:00
parent a57d30c680
commit 00cc3066a2
10 changed files with 95 additions and 9 deletions

View File

@ -3,7 +3,9 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
const ExtendedVideoPlayer = React.createClass({ const ExtendedVideoPlayer = React.createClass({
propTypes: { propTypes: {
src: React.PropTypes.string.isRequired src: React.PropTypes.string.isRequired,
controls: React.PropTypes.bool.isRequired,
muted: React.PropTypes.bool.isRequired
}, },
mixins: [PureRenderMixin], mixins: [PureRenderMixin],
@ -11,7 +13,7 @@ const ExtendedVideoPlayer = React.createClass({
render () { render () {
return ( return (
<div> <div>
<video src={this.props.src} autoPlay muted loop /> <video src={this.props.src} autoPlay muted={this.props.muted} controls={this.props.controls} loop />
</div> </div>
); );
}, },

View File

@ -25,6 +25,7 @@ const Status = React.createClass({
onReblog: React.PropTypes.func, onReblog: React.PropTypes.func,
onDelete: React.PropTypes.func, onDelete: React.PropTypes.func,
onOpenMedia: React.PropTypes.func, onOpenMedia: React.PropTypes.func,
onOpenVideo: React.PropTypes.func,
onBlock: React.PropTypes.func, onBlock: React.PropTypes.func,
me: React.PropTypes.number, me: React.PropTypes.number,
boostModal: React.PropTypes.bool, boostModal: React.PropTypes.bool,
@ -76,7 +77,7 @@ const Status = React.createClass({
if (status.get('media_attachments').size > 0 && !this.props.muted) { if (status.get('media_attachments').size > 0 && !this.props.muted) {
if (status.getIn(['media_attachments', 0, 'type']) === 'video') { if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
media = <VideoPlayer media={status.getIn(['media_attachments', 0])} sensitive={status.get('sensitive')} />; media = <VideoPlayer media={status.getIn(['media_attachments', 0])} sensitive={status.get('sensitive')} onOpenVideo={this.props.onOpenVideo} />;
} else { } else {
media = <MediaGallery media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} />; media = <MediaGallery media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} />;
} }

View File

@ -6,7 +6,8 @@ import { isIOS } from '../is_mobile';
const messages = defineMessages({ const messages = defineMessages({
toggle_sound: { id: 'video_player.toggle_sound', defaultMessage: 'Toggle sound' }, toggle_sound: { id: 'video_player.toggle_sound', defaultMessage: 'Toggle sound' },
toggle_visible: { id: 'video_player.toggle_visible', defaultMessage: 'Toggle visibility' } toggle_visible: { id: 'video_player.toggle_visible', defaultMessage: 'Toggle visibility' },
expand_video: { id: 'video_player.expand', defaultMessage: 'Expand video' }
}); });
const videoStyle = { const videoStyle = {
@ -61,6 +62,15 @@ const spoilerButtonStyle = {
zIndex: '100' zIndex: '100'
}; };
const expandButtonStyle = {
position: 'absolute',
bottom: '6px',
right: '8px',
color: 'white',
textShadow: "0px 1px 1px black, 1px 0px 1px black",
zIndex: '100'
};
const VideoPlayer = React.createClass({ const VideoPlayer = React.createClass({
propTypes: { propTypes: {
media: ImmutablePropTypes.map.isRequired, media: ImmutablePropTypes.map.isRequired,
@ -68,7 +78,8 @@ const VideoPlayer = React.createClass({
height: React.PropTypes.number, height: React.PropTypes.number,
sensitive: React.PropTypes.bool, sensitive: React.PropTypes.bool,
intl: React.PropTypes.object.isRequired, intl: React.PropTypes.object.isRequired,
autoplay: React.PropTypes.bool autoplay: React.PropTypes.bool,
onOpenVideo: React.PropTypes.func.isRequired
}, },
getDefaultProps () { getDefaultProps () {
@ -116,6 +127,13 @@ const VideoPlayer = React.createClass({
}); });
}, },
handleExpand () {
const node = ReactDOM.findDOMNode(this).querySelector('video');
node.pause();
this.props.onOpenVideo(this.props.media);
},
setRef (c) { setRef (c) {
this.video = c; this.video = c;
}, },
@ -159,6 +177,12 @@ const VideoPlayer = React.createClass({
</div> </div>
); );
let expandButton = (
<div style={expandButtonStyle} >
<IconButton title={intl.formatMessage(messages.expand_video)} icon='expand' onClick={this.handleExpand} />
</div>
);
let muteButton = ''; let muteButton = '';
if (this.state.hasAudio) { if (this.state.hasAudio) {
@ -202,6 +226,7 @@ const VideoPlayer = React.createClass({
<div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${width}px`, height: `${height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}> <div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${width}px`, height: `${height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}>
{spoilerButton} {spoilerButton}
{muteButton} {muteButton}
{expandButton}
<video ref={this.setRef} src={media.get('url')} autoPlay={!isIOS()} loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} /> <video ref={this.setRef} src={media.get('url')} autoPlay={!isIOS()} loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} />
</div> </div>
); );

View File

@ -75,6 +75,10 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(openModal('MEDIA', { media, index })); dispatch(openModal('MEDIA', { media, index }));
}, },
onOpenVideo (media) {
dispatch(openModal('VIDEO', { media }));
},
onBlock (account) { onBlock (account) {
dispatch(blockAccount(account.get('id'))); dispatch(blockAccount(account.get('id')));
}, },

View File

@ -17,7 +17,8 @@ const DetailedStatus = React.createClass({
propTypes: { propTypes: {
status: ImmutablePropTypes.map.isRequired, status: ImmutablePropTypes.map.isRequired,
onOpenMedia: React.PropTypes.func.isRequired onOpenMedia: React.PropTypes.func.isRequired,
onOpenVideo: React.PropTypes.func.isRequired,
}, },
mixins: [PureRenderMixin], mixins: [PureRenderMixin],
@ -39,7 +40,7 @@ const DetailedStatus = React.createClass({
if (status.get('media_attachments').size > 0) { if (status.get('media_attachments').size > 0) {
if (status.getIn(['media_attachments', 0, 'type']) === 'video') { if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
media = <VideoPlayer sensitive={status.get('sensitive')} media={status.getIn(['media_attachments', 0])} width={300} height={150} autoplay />; media = <VideoPlayer sensitive={status.get('sensitive')} media={status.getIn(['media_attachments', 0])} width={300} height={150} onOpenVideo={this.props.onOpenVideo} autoplay />;
} else { } else {
media = <MediaGallery sensitive={status.get('sensitive')} media={status.get('media_attachments')} height={300} onOpenMedia={this.props.onOpenMedia} />; media = <MediaGallery sensitive={status.get('sensitive')} media={status.get('media_attachments')} height={300} onOpenMedia={this.props.onOpenMedia} />;
} }

View File

@ -112,6 +112,10 @@ const Status = React.createClass({
this.props.dispatch(openModal('MEDIA', { media, index })); this.props.dispatch(openModal('MEDIA', { media, index }));
}, },
handleOpenVideo (media) {
this.props.dispatch(openModal('VIDEO', { media }));
},
handleReport (status) { handleReport (status) {
this.props.dispatch(initReport(status.get('account'), status)); this.props.dispatch(initReport(status.get('account'), status));
}, },
@ -151,7 +155,7 @@ const Status = React.createClass({
<div className='scrollable'> <div className='scrollable'>
{ancestors} {ancestors}
<DetailedStatus status={status} me={me} onOpenMedia={this.handleOpenMedia} /> <DetailedStatus status={status} me={me} onOpenVideo={this.handleOpenVideo} onOpenMedia={this.handleOpenMedia} />
<ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} /> <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} />
{descendants} {descendants}

View File

@ -111,7 +111,7 @@ const MediaModal = React.createClass({
if (attachment.get('type') === 'image') { if (attachment.get('type') === 'image') {
content = <ImageLoader src={url} imgProps={{ style: { display: 'block' } }} />; content = <ImageLoader src={url} imgProps={{ style: { display: 'block' } }} />;
} else if (attachment.get('type') === 'gifv') { } else if (attachment.get('type') === 'gifv') {
content = <ExtendedVideoPlayer src={url} />; content = <ExtendedVideoPlayer src={url} muted={true} controls={false} />;
} }
return ( return (

View File

@ -1,10 +1,12 @@
import PureRenderMixin from 'react-addons-pure-render-mixin'; import PureRenderMixin from 'react-addons-pure-render-mixin';
import MediaModal from './media_modal'; import MediaModal from './media_modal';
import VideoModal from './video_modal';
import BoostModal from './boost_modal'; import BoostModal from './boost_modal';
import { TransitionMotion, spring } from 'react-motion'; import { TransitionMotion, spring } from 'react-motion';
const MODAL_COMPONENTS = { const MODAL_COMPONENTS = {
'MEDIA': MediaModal, 'MEDIA': MediaModal,
'VIDEO': VideoModal,
'BOOST': BoostModal 'BOOST': BoostModal
}; };

View File

@ -0,0 +1,46 @@
import LoadingIndicator from '../../../components/loading_indicator';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ExtendedVideoPlayer from '../../../components/extended_video_player';
import { defineMessages, injectIntl } from 'react-intl';
import IconButton from '../../../components/icon_button';
const messages = defineMessages({
close: { id: 'lightbox.close', defaultMessage: 'Close' }
});
const closeStyle = {
position: 'absolute',
zIndex: '100',
top: '4px',
right: '4px'
};
const VideoModal = React.createClass({
propTypes: {
media: ImmutablePropTypes.map.isRequired,
onClose: React.PropTypes.func.isRequired,
intl: React.PropTypes.object.isRequired
},
mixins: [PureRenderMixin],
render () {
const { media, intl, onClose } = this.props;
const url = media.get('url');
return (
<div className='modal-root__modal media-modal'>
<div>
<IconButton title={intl.formatMessage(messages.close)} icon='times' onClick={onClose} size={16} style={closeStyle} />
<ExtendedVideoPlayer src={url} muted={false} controls={true} />
</div>
</div>
);
}
});
export default injectIntl(VideoModal);

View File

@ -124,6 +124,7 @@ const en = {
"upload_progress.label": "Uploading...", "upload_progress.label": "Uploading...",
"video_player.toggle_sound": "Toggle sound", "video_player.toggle_sound": "Toggle sound",
"video_player.toggle_visible": "Toggle visibility", "video_player.toggle_visible": "Toggle visibility",
"video_player.expand": "Expand video",
}; };
export default en; export default en;