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

Static button with Dom Overlay, how to pass click event back? #418

Closed caltv closed 6 years ago

caltv commented 6 years ago

I am using Dom Overlay to overlay a static button, using the approach described here

https://stackoverflow.com/questions/47481075/static-buttons-in-react-vr/47556143?noredirect=1#comment82550584_47556143

My issue is that when the button is clicked I can't pass the click event back to index.vr.js, is there a way to do that?

Thanks

andrewimm commented 6 years ago

There are a variety of ways to communicate between the browser window and your react app. This example illustrates a number of them: https://github.com/facebook/react-vr/blob/master/Examples/NativeModules/index.vr.js

The easiest way is to send a click from the dom overlay back to React is to send an event via RCTDeviceEventEmitter. If you have access to your React Native Context object, you can trigger these events. Take a look at the ControllerInfo module, which sends events to React when a gamepad is connected or disconnected: https://github.com/facebook/react-vr/blob/a284d2b8e27b039154586fbe4aa6fab9ad930e83/ReactVR/js/Modules/ControllerInfo.js#L50 . That'd be a good starting point