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

fix(overlay): make overlay work in fullscreen mode #1653

Closed
wants to merge 8 commits into from

Conversation

quanterion
Copy link
Contributor

@quanterion quanterion commented Oct 29, 2016

This allows all overlay-based components like dialog, menu, tooltip etc work in full screen mode https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen

Implementation moves overlay container into fullscreen element and back to document.body as user navigates between fullscreen and non-fullscreen modes. Apps not using fullscreen mode are unaffected.

fixes #1628

PS: I added Fullscreen button near to RTL one to test fix across all components
PPS: I have no idea about tests for this fix, any advice?

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 29, 2016
@jelbourn jelbourn self-assigned this Nov 1, 2016
@quanterion
Copy link
Contributor Author

@jelbourn can you review my PR? It would be great to have this fix in next release.

@jelbourn
Copy link
Member

jelbourn commented Nov 8, 2016

@quanterion working my way here- I need to set aside a chunk of time to look at the issue.

@jelbourn
Copy link
Member

Thanks for your patience on this one. I took a look at the issue and think a cleaner approach would be to introduce a new type of OverlayContainer that handles the fullscreen parts. It would look something like this:

@Injectable()
export class FullscreenFriendlyOverlayContainer extends OverlayContainer {
  protected _createContainer(): void {
    super._createContainer();

    this._addFullscreenChangeListener(() => this._adjustParentForFullscreenChange());
  }

  private _adjustParentForFullscreenChange(): void {
    if (!this._containerElement) {
      return;
    }

    let fullscreenElement = this._getFullscreenElement();
    let parent = fullscreenElement || document.body;
    parent.appendChild(this._containerElement);
  }

  private _addFullscreenChangeListener(fn: () => void) {
    if (document.fullscreenEnabled) {
      document.addEventListener('fullscreenchange', fn);
    } else if (document.webkitFullscreenEnabled) {
      document.addEventListener('webkitfullscreenchange', fn);
    } else if ((document as any).mozFullScreenEnabled) {
      document.addEventListener('mozfullscreenchange', fn);
    } else if ((document as any).msFullscreenEnabled) {
      document.addEventListener('MSFullscreenChange', fn);
    }
  }

  private _getFullscreenElement(): Element {
    return document.fullscreenElement ||
        document.webkitFullscreenElement ||
        (document as any).mozFullScreenElement ||
        (document as any).msFullscreenElement ||
        null;
  }
}

To use this container instead of the default, you would add a new provider to your app:

providers: [
  {provide: OverlayContainer, useClass: FullscreenFriendlyOverlayContainer},
]

Doing it this way has a couple of advantages:

  • All of the code dealing with fullscreen is encapsulated within a single class.
  • If an app isn't using FullscreenFriendlyOverlayContainer, the code can be completely dropped by optimizers like Closure Compiler and rollup. This is good, since most apps don't need to deal with fullscreen.

Would you be willing up update your PR to use this approach and add the appropriate tests / comments / docs?

@quanterion
Copy link
Contributor Author

quanterion commented Nov 21, 2016

@jelbourn implemented it in a new PR #1949, please close this

@jelbourn jelbourn closed this Nov 22, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(menu): menu doesn't work in full screen mode
3 participants