sindresorhus / screenfull

Simple wrapper for cross-browser usage of the JavaScript Fullscreen API
https://sindresorhus.com/screenfull
MIT License
7.08k stars 698 forks source link

Fullscreen change event does not set isFullscreen #186

Closed enjikaka closed 3 years ago

enjikaka commented 3 years ago

After going into fullscreen, in the callback onchange, getting isFullscreen returs undefined in v 5.1.0

sindresorhus commented 3 years ago

.isFullscreen literally cannot return undefined: https://github.com/sindresorhus/screenfull.js/blob/eddb5fc63d74b714edabe7829f5b0e007eb1689c/src/screenfull.js#L154-L158 There's something else going on.

eliasbg commented 3 years ago

Hello,

I have the same problem. the isFullscreen property does not exist.

import * as screenfull from 'screenfull';

export class AppComponent implements OnInit {
isFullScreen: boolean | undefined;

  ngOnInit() : void {
    if (screenfull.isEnabled) {
      screenfull.on('change', () => {
        this.isFullScreen = screenfull.isFullscreen;
      })
    }  
  }
}
Error: src/app/app.component.ts:16:40 - error TS2339: Property 'isFullscreen' does not exist on type 'Screenfull | { isEnabled: false; }'.
  Property 'isFullscreen' does not exist on type '{ isEnabled: false; }'.

16         this.isFullScreen = screenfull.isFullscreen;
frontsomni commented 3 years ago

@eliasbg

open screenfull.d.ts file

find screenfull declare (about 169 lines):

declare let screenfull: screenfull.Screenfull | {isEnabled: false};

fix:

declare let screenfull: screenfull.Screenfull;

you can access isFullscreen property