facebookarchive / react-360

Create amazing 360 and VR content using React
https://facebook.github.io/react-360
Other
8.73k stars 1.23k forks source link

onEnterVR / inVR no longer works #586

Open moroneyk opened 6 years ago

moroneyk commented 6 years ago

Bug : onEnterVR / inVR no longer works

When pressing the 'View in VR' button no event is fired to tell us we are in VR. Normally listening for a onEnterVR / onExitVR would let us know if the user has entered or exited VR mode.

This even should be fired from VRInstance.js from the _onEnterVR() and _onExitVR() functions as the user enters/exits VR. Code is below:


  _onEnterVR() {
    this.rootView.context &&
      this.rootView.context.callFunction('RCTDeviceEventEmitter', 'emit', ['onEnterVR', []]);
  }

  _onExitVR() {
    this.rootView.context &&
      this.rootView.context.callFunction('RCTDeviceEventEmitter', 'emit', ['onExitVR', []]);
  }

Expected behavior

Listening for an 'onEnterVR' or 'onExitVR' event should let us know if the user has entered/exited VR mode.

Actual behaviour

'onEnterVR' or 'onExitVR' events are never fired by VRInstance

Reproduction

Add an RCTDeviceEventEmitter listener for 'onEnterVR' or 'onExitVR' to any project. Then enter exit VR Mode. No events are intercepted.

Solution

Ensure the 'onEnterVR' or 'onExitVR' calls are fired when entering exiting VR, or document any other recommended methods to determine if the user has entered/exited VR.

Additional Information

AidenFaulconer commented 5 years ago

Unsure if this will work, as I have been trying to implement it myself. But through MDN documentation on WebVR they mention an event listener as follows... window.addEventListener('vrdisplaypresentchange', () => { if(VRDisplay.isPresenting) { console.warn('Display has started presenting.'); } else { console.warn('Display has stopped presenting.'); } });