-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
feat: playerresize event in all cases #4864
Conversation
One thing to consider as well here is that we're going to get multiple |
This reverts commit e0ed0b5.
src/js/resize-manager.js
Outdated
let RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window.ResizeObserver; | ||
|
||
if (options.ResizeObserver === null) { | ||
RESIZE_OBSERVER_AVAILABLE = false; |
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.
wouldn't this set RESIZE_OBSERVER_AVAILABLE
to false even when one is available through window.ResizeObserver
?
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.
Yup, the idea is if you wanted to disable the ResizeObserver for whatever reason you could pass in null
.
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.
Gotcha. I'd suggest a comment over this block so it's clear for future readers 😄
* @event Player#playerresize | ||
* @type {EventTarget~Event} | ||
*/ | ||
this.trigger('playerresize'); |
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.
I believe the event trigger would have worked in IE8 as well - since we're reverting this for the ResizeObserver and that's only available after IE8, is this a breaking change?
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.
We are falling back to using an iframe for playerresize events when ResizeObserver isn't available, currently, that's basically everywhere, though, chrome will be shipping ResizeObserver soon.
test/unit/resize-manager.test.js
Outdated
this.player.on('playerresize', function() { | ||
playerresizeCalled++; | ||
}); | ||
rm.resizeObserver_.observer(); |
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.
observe
?
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.
actually looks like you don't need this line at all
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.
I set this in the constructor of MyResizeObserver, calling it calls the observe handler which will trigger playerresize
which we can then test. Maybe I should just make it a local variable to be more obvious what is going on.
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.
Ah, I see. I agree that making it a local variable will make it more clear
assert.equal(playerresizeCalled, 1, 'playerresize was triggered'); | ||
|
||
rm.dispose(); | ||
}); |
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.
one good test to add would be a test that makes sure a resizeObserver is created when one is available on the window
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.
It would be nice but mocking out window
is a pain :)
src/js/resize-manager.js
Outdated
let RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window.ResizeObserver; | ||
|
||
if (options.ResizeObserver === null) { | ||
RESIZE_OBSERVER_AVAILABLE = false; |
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.
Gotcha. I'd suggest a comment over this block so it's clear for future readers 😄
test/unit/resize-manager.test.js
Outdated
this.player.on('playerresize', function() { | ||
playerresizeCalled++; | ||
}); | ||
rm.resizeObserver_.observer(); |
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.
Ah, I see. I agree that making it a local variable will make it more clear
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.
One minor question that I don't think affects my approval of this PR. 👍
return super.createEl('iframe', { | ||
className: 'vjs-resize-manager' | ||
}); | ||
} |
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.
I believe the element will be created even when it's not needed. Should we suppress the creation of it when ResizeObserver
is available?
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.
This line in the constructor will make it so no element is created if ResizeObserver is used: https://github.com/videojs/video.js/pull/4864/files#diff-8947c14c969c2d82a892c5fac0d0efd0R19
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.
Oh, I didn't notice that. Carry on. 👍
Updated based on comments and added docs.
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.
Made a few small typo corrections, but at this point LGTM
QA-LGTM |
Use ResizeObserver when available for better and more performant resizing information, otherwise, fall back to a throttled
resize
event on an iframe that's the size of the player.Allows a video.js user to disable this by setting
resizeManager: false
as an option since the component will not be initialized.This probably needs to revert #4800 (e0ed0b5) because we end up getting two
playerresize
events with the dimension methods now.TODO: