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

Linking to a new browser tab #318

Open hendrasan opened 7 years ago

hendrasan commented 7 years ago

I have a VrButton with onClick event that does NativeModules.LinkingManager.openURL('<url>'); and it works.

But as I test this on browser (and mobile browser), I'd like the VrButton to open the URL in a new tab. I searched on the documentation and the source code but there's no mention of it.

Is this possible?

Thanks

andrewimm commented 7 years ago

Chances are, it would get blocked by popup blockers. Those are driven by JavaScript attempting to open new windows or tabs. I'll look into what it would take to add this, though.

ctoLarsson commented 7 years ago

+1 on this feature, actually quite important. I also tried many ways to get a link to open a new tab but I couldn't get it working.

Funnily, it is the opposite of general web browsing, where opening new tabs feels unexpected. Now it feels unexpected that clicking a link doesn't open a new tab, and instead closed the VR experience.

Try the last scene of this demo. Hovering the Heart and clicking the GitHub link, it feels unexpected that VR quits, doesn't it? I feel so. Also means links can just be placed in the end of a tour, otherwise when pressing Back the whole VR environment has to restart. https://livetourlab.com/tours/3004

So a big 👍 +1 if it can be solved. :-)

mahashouman commented 6 years ago

Any updates on this feature? I would love to be able to add linkout CTAs.

Manny-Mobfish commented 6 years ago

We would also need it very soon +1, for this feature request.

andrewimm commented 6 years ago

This is very easy to implement on your own with Native Modules, but again there's a good chance it can be blocked by popup blockers because browsers do not typically allow JavaScript to open new windows.

Basic pseudocode (untested, but you get the gist):

import {Module} from 'react-360-web';

class CustomLinkingModule extends Module {
  constructor() {
    super('CustomLinkingModule');
  }

  openInNewTab(url) {
    window.open(url, '_blank');
  }
}

Then you can call NativeModules.CustomLinkingModule.openInNewTab('https://example.net') from React.

Manny-Mobfish commented 6 years ago

This is exactly how I implement it for now. But the browser is blocking the "popup" since the onClick on VrButtons doesn't seems to be a trusted event.

Is there anything we can do about it?

olli1337 commented 6 years ago

Thumbs up for this request!

olli1337 commented 6 years ago

https://github.com/facebook/react-360/issues/183#issuecomment-304142112 this satisfied my needs for now.