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

Video-docking: Implement drag and drop #10394

Merged
merged 2 commits into from
Jul 28, 2017

Conversation

wassgha
Copy link
Contributor

@wassgha wassgha commented Jul 12, 2017

Implements dragging for docked videos.

Changes

  • Viewport is now an instance variable
  • Corrected JSDoc on video analytics
  • Implemented drag & drop for all players (used a mask to capture events on iframe players)
  • Video placeholder only appears when video docking starts (corrects bug where a dark line would appear over and under the video if the aspect ratio isn't correct)
  • Changed minimized video's z-index

To-do in next PRs

  • Add minimized controls
  • Show the draggable mask since docking starts (so that it absorbs click / mouseover events and hides the video controls)
  • Call unlisteners for touch and mouse events when dragging is over
  • Explore switching to position: sticky for cleaner code

Closes #9962, Checks off an item on #4154, Checks off two items on #8088

@wassgha wassgha force-pushed the video-dock-dragging branch 2 times, most recently from 2b526b2 to 1b9d238 Compare July 12, 2017 23:16
@wassgha wassgha requested a review from aghassemi July 12, 2017 23:35
@wassgha wassgha changed the title Video dock dragging Video-docking: Implement drag and drop Jul 13, 2017
@wassgha wassgha closed this Jul 19, 2017
@aghassemi
Copy link
Contributor

@wassgha planning a different PR for this?

@wassgha
Copy link
Contributor Author

wassgha commented Jul 19, 2017 via email

@wassgha wassgha reopened this Jul 19, 2017
@wassgha
Copy link
Contributor Author

wassgha commented Jul 19, 2017

Ready for review once Travis passes

@wassgha wassgha force-pushed the video-dock-dragging branch 3 times, most recently from 9e4ec25 to 67bb5ad Compare July 19, 2017 23:03
@wassgha
Copy link
Contributor Author

wassgha commented Jul 24, 2017

Updated description

@@ -894,13 +945,235 @@ class VideoEntry {
// Update docking state
if (this.scrollMap_(DOCK_SCALE, 1) == DOCK_SCALE) {
this.dockState_ = DockStates.DOCKED;
this.initializeDragging_();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is measuring, which we don't wanna do during a mutate, needs to go to its own measure block.

@@ -894,13 +945,235 @@ class VideoEntry {
// Update docking state
if (this.scrollMap_(DOCK_SCALE, 1) == DOCK_SCALE) {
this.dockState_ = DockStates.DOCKED;
this.initializeDragging_();
this.drag_();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm, drag_() keeps running every rAF, not great. We need to only run it with touch move.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to run every RAF for the momentum drag to kick in (so that it moves the element even after the user is no longer dragging until the velocity is null).

return;
}

const minimizedRect = this.internalElement_./*OK*/getBoundingClientRect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep drag_ a mutate-only function. Does it need to read this every time? can it by cached by initializeDragging_?


// Re-run on every animation frame
this.vsync_.mutate(() => {
this.drag_();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto comment above, we should only happen with touch move.

* @param {boolean} updateDisplacement
* @private
*/
mouse_(e, updateDisplacement = false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to comments above, we really need to separate measure and mutate and tied to events instead of running every rAF. How about something like:

1- video docked
2- initilaizeDragdrop (in a measure block, cache whatever we need, install handlers, on touchmove call dragtouchmove_
3- dragtouchmove_ does reads new coordinates from e and does a mutate (if we needed to reread anything then split it does both a measure and mutate)

We just wanna make sure we never measure during mutate and vice versa.

@wassgha wassgha force-pushed the video-dock-dragging branch 2 times, most recently from 7ff67a6 to b738852 Compare July 27, 2017 01:22
}

.i-amphtml-dockable-video > video.i-amphtml-dockable-video-minimizing,
.i-amphtml-dockable-video > iframe.i-amphtml-dockable-video-minimizing {
position: fixed;
height: auto;
overflow: hidden;
z-index: 2;
z-index: 16;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run gulp get-zindex. it will regenerated the Z_INDEX.md file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :) Should be ready to merge.

@aghassemi aghassemi merged commit 6aa61ab into ampproject:master Jul 28, 2017
@aghassemi
Copy link
Contributor

merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants