-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pop-out player for audio/video in web UI (#14870)
Fix #11160
- Loading branch information
Showing
20 changed files
with
648 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// @ts-check | ||
|
||
export const PICTURE_IN_PICTURE_DEPLOY = 'PICTURE_IN_PICTURE_DEPLOY'; | ||
export const PICTURE_IN_PICTURE_REMOVE = 'PICTURE_IN_PICTURE_REMOVE'; | ||
|
||
/** | ||
* @typedef MediaProps | ||
* @property {string} src | ||
* @property {boolean} muted | ||
* @property {number} volume | ||
* @property {number} currentTime | ||
* @property {string} poster | ||
* @property {string} backgroundColor | ||
* @property {string} foregroundColor | ||
* @property {string} accentColor | ||
*/ | ||
|
||
/** | ||
* @param {string} statusId | ||
* @param {string} accountId | ||
* @param {string} playerType | ||
* @param {MediaProps} props | ||
* @return {object} | ||
*/ | ||
export const deployPictureInPicture = (statusId, accountId, playerType, props) => ({ | ||
type: PICTURE_IN_PICTURE_DEPLOY, | ||
statusId, | ||
accountId, | ||
playerType, | ||
props, | ||
}); | ||
|
||
/* | ||
* @return {object} | ||
*/ | ||
export const removePictureInPicture = () => ({ | ||
type: PICTURE_IN_PICTURE_REMOVE, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/javascript/mastodon/components/picture_in_picture_placeholder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Icon from 'mastodon/components/icon'; | ||
import { removePictureInPicture } from 'mastodon/actions/picture_in_picture'; | ||
import { connect } from 'react-redux'; | ||
import { debounce } from 'lodash'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
export default @connect() | ||
class PictureInPicturePlaceholder extends React.PureComponent { | ||
|
||
static propTypes = { | ||
width: PropTypes.number, | ||
dispatch: PropTypes.func.isRequired, | ||
}; | ||
|
||
state = { | ||
width: this.props.width, | ||
height: this.props.width && (this.props.width / (16/9)), | ||
}; | ||
|
||
handleClick = () => { | ||
const { dispatch } = this.props; | ||
dispatch(removePictureInPicture()); | ||
} | ||
|
||
setRef = c => { | ||
this.node = c; | ||
|
||
if (this.node) { | ||
this._setDimensions(); | ||
} | ||
} | ||
|
||
_setDimensions () { | ||
const width = this.node.offsetWidth; | ||
const height = width / (16/9); | ||
|
||
this.setState({ width, height }); | ||
} | ||
|
||
componentDidMount () { | ||
window.addEventListener('resize', this.handleResize, { passive: true }); | ||
} | ||
|
||
componentWillUnmount () { | ||
window.removeEventListener('resize', this.handleResize); | ||
} | ||
|
||
handleResize = debounce(() => { | ||
if (this.node) { | ||
this._setDimensions(); | ||
} | ||
}, 250, { | ||
trailing: true, | ||
}); | ||
|
||
render () { | ||
const { height } = this.state; | ||
|
||
return ( | ||
<div ref={this.setRef} className='picture-in-picture-placeholder' style={{ height }} role='button' tabIndex='0' onClick={this.handleClick}> | ||
<Icon id='window-restore' /> | ||
<FormattedMessage id='picture_in_picture.restore' defaultMessage='Put it back' /> | ||
</div> | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d88a79b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to make the pop-out player movable? It will sometimes hide the "writing toots" button on mobile or people's replies on PC...