Skip to content

Commit

Permalink
refactor(media_control): avoid hide during one user interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopaulovieira committed May 23, 2021
1 parent 614d82f commit d0103de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/base/media_control/media_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class MediaControlPlugin extends UICorePlugin {
'mouseleave .media-control__elements': 'removeKeepVisible',
}
const touchOnlyEvents = {
'touchstart .media-control__elements': 'setKeepVisible',
'touchstart .media-control__elements': 'onTouchStart',
'touchend .media-control__elements': 'removeKeepVisible',
}

Expand Down Expand Up @@ -83,6 +83,12 @@ export default class MediaControlPlugin extends UICorePlugin {
this.playback && playbackEventListenerData.forEach(item => this.listenToOnce(item.object, item.event, item.callback))
}

onTouchStart() {
// Avoids to hide if the user taps into one media control element
clearTimeout(this._hideId)
this.setKeepVisible()
}

setKeepVisible() {
if (!this._isVisible) return
this._keepVisible = true
Expand Down
10 changes: 10 additions & 0 deletions src/base/media_control/media_control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ describe('MediaControl Plugin', () => {
})
})

describe('onTouchStart callback', () => {
test('calls setKeepVisible method', () => {
const { plugin } = setupTest()
jest.spyOn(plugin, 'setKeepVisible')
plugin.onTouchStart()

expect(plugin.setKeepVisible).toHaveBeenCalledTimes(1)
})
})

describe('setKeepVisible method', () => {
test('ignores the invocation if _isVisible internal flag is false', () => {
const { plugin } = setupTest()
Expand Down

0 comments on commit d0103de

Please sign in to comment.