Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Customizable delay time for auto hide of ControlBar #233

Merged
merged 2 commits into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -22,6 +22,7 @@
"react/destructuring-assignment": "off",
"react/forbid-prop-types": "off",
"react/jsx-filename-extension": "off",
"react/jsx-one-expression-per-line": "literal",
"react/no-find-dom-node": "off",
"react/no-unused-prop-types": "off",
"react/require-default-props": "off",
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
@@ -1,5 +1,4 @@
{
"eslint.autoFixOnSave": true,
"prettier.eslintIntegration": true,
"javascript.validate.enable": false,
"editor.rulers": [
Expand Down
10 changes: 8 additions & 2 deletions docs/lib/Components/ControlBarPage.js
Expand Up @@ -32,10 +32,16 @@ export default class ControlBarPage extends React.Component {
{`ControlBar.propTypes = {

// Hide the control bar automatically after the player is inactive
// default: 'true'
// default: true
autoHide: PropTypes.bool,
// The waiting time for auto hide after player is inactive (in milliseconds)
// default: 3000
autoHideTime: PropType.number,
// Do not render default controls, only use custom ones provided as children of <ControlBar>
// default: false
disableDefaultControls: PropTypes.bool,
// Do not render the control bar if set it to true
// default: 'false'
// default: false
disableCompletely: PropTypes.bool,

}`}
Expand Down
14 changes: 13 additions & 1 deletion src/components/Player.js
Expand Up @@ -335,11 +335,23 @@ export default class Player extends Component {
}

startControlsTimer() {
let controlBarActiveTime = 3000;
React.Children.forEach(this.props.children, element => {
if (!React.isValidElement(element) || element.type !== ControlBar) {
return;
}

const { autoHideTime } = element.props;
if (typeof autoHideTime === 'number') {
controlBarActiveTime = autoHideTime;
}
});

this.actions.userActivate(true);
clearTimeout(this.controlsHideTimer);
this.controlsHideTimer = setTimeout(() => {
this.actions.userActivate(false);
}, 3000);
}, controlBarActiveTime);
}

handleStateChange(state, prevState) {
Expand Down
1 change: 1 addition & 0 deletions src/components/control-bar/ControlBar.js
Expand Up @@ -18,6 +18,7 @@ import { mergeAndSortChildren } from '../../utils';
const propTypes = {
children: PropTypes.any,
autoHide: PropTypes.bool,
autoHideTime: PropTypes.number, // used in Player
disableDefaultControls: PropTypes.bool,
disableCompletely: PropTypes.bool,
className: PropTypes.string
Expand Down