Can you display a popup modal inside a react-three-fiber canvas? - reactjs

I am trying to extend this react-three-fiber Game Demo. I want to show a popup modal when the player interacts with a computer. I want to render different React components inside the modal that are styled using TailwindCSS.
Do you know if this is something you can do with react-three-fiber? Any help would be appreciated!

As far as I know, you can't render DOM-elements directly with three.js.
As a workaround, you can create images of your react components for example with html2canvas. Then you use these images as textures for a 2D plane.

Yes it is possible,
If you want to render the element as a game element you can look at sprites or the drei billboards.
drei billboard
If you want to render it as html it's even easier, just put your dom elements outside of the react three fiber canvas element.
like so :
<div>
{showElementState&&<div><input type="range" ref={someRef}/></div>}
<Canvas>
<mesh onClick={()=>setShowElementState(true)} >
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={'orange'} />
</mesh>
</Canvas>
</div>
or you could also just use the leva package(which is recommended on the react-three-fiber github):
https://github.com/pmndrs/leva

This is a simple enough solve, while three.js doesn't render DOM elements it can still be used to manipulate elements already in the DOM. So if you want to change the display of an elements, or have it translate and follow a 3D object this is easy enough with vanilla three.
Lucky for you you have access to all the perks of three-fiber so I would say just use the Drei Html component. I'll just leave the storybook here, it should go over any questions you have for it
Html Storybook Drei

Related

How to create image slider with webgl textures in react three fiber

I am currently trying to transition through an array of images using webgl shaders and react three fiber and I am stuck. Trying to use buttons to navigate through rather than just clicking on the canvas. Unsure how to pass / change imageOne and imageTwo with left and right arrow. Is this possible?
I'm aware how to do an image slider in react alone but confused with the two image properties for the glsl mix property. All help is appreciated.
Inspiration: https://yuta-takahashi.dev/
Sandbox: https://codesandbox.io/s/snowy-cdn-os34di?file=/pages/index.js

How to render a pure component dynamically in React?

I'm trying to render some pure components / a component which are basically RE charts in a carousel. So far I have implemented with images, but when I'm passing pure component / a component it is not showing anything.
I have created a sandbox which is having all the code which I have written so far with all the details SCSS, Re chart component and a main component. Please have a look and let me know what I'm missing or is there any other way where I can render components in a carousel.
Codesandbox URL
I'm not sure if this is what you are looking for.
Check my sandbox
The problem is that you need to define exactly the width and height of the svg also at its "containers", meaning that style={{ width: 500, height: 300 }} needs to be applied to li and ul too.
Also i changed a little bit the transform slide width.

Div overflow logic in SVG?

The Context
Working on a database schema editor in SVG which may have
lot of records in some table , i am looking to add scrollbars to
the table. The whole thing is coded in SVG and integrated in a ReactJS
app within a container as a SVG document.
The Question
How could i get scrollbars like for instance scrolling the children
of a where bounds would tell the viewport size and
the children would determine the scrollable area?
I don't think this make much sense in SVG which is about 'painting' , however due to its increased popularity maybe something has been implemented about this?
Any ideas?
Regards
Philippe
I tried overflow='auto' on but it did not do the trick.
See code below in ReactJS
<svg>
<g overflow={'auto'} width={100} height={100} id={'test1'}>
<DivSvg top={255} left={25} width={100} height={100} backgroundColor={'green'}/>
</g>
</svg>
I thought maybe overflow='auto' would make evaluate its size based on width/height and scroll the DivSvg ( i.e. ) which otherwise does not fit into the
someone in our company found the right approach.
Actually svg can integrate HTML within rectangular areas known as ''
Thanks to this i can draw my diagram in SVG while keeping table display coded in HTML and they work properly alltogether to rely both on SVG graphical skills VS HTML table content styling , scrolling , ...

React-Leaflet React Component as Marker

I've recently gotten into React Leaflet and from what I've gathered from the docs, it is not possible to add a custom React Element (Component or pure functional) as a marker.
What I want to achieve is to be able to use my React Element which is an SVG icon as the marker. This would be useful because I'll need to display several different color icons and it's way more convenient to pass the color as props and let React create the marker.
Am I right in assuming this isn't possible?
You are incorrect! :) React-leaflet allows the creation of custom components. Also, you should check out react-leaflet-div-icon since it seems like it's exactly what you need.

Prevent re-initializing when moving react element

I'm trying to animate a MapView in React Native so that when it's pressed, it goes from being an element in a ScrollView to the map covering the entire screen (including navigation and status bars).
For the overlay view I'm using react-native-overlay
I've got it sort of working by:
measuring the map position with UIManager.measure
activating the overlay and rendering the same map but now inside an overlay
positioning the map relative to the overlay based on measurement
animating the map size to cover the entire screen
The problem is that when going to/from overlay, the entire map reloads which effectively kills the magic of the animation.
From what I understand, since I move the MapView pretty far in the VDOM tree, React kills it and inits a new one. I've tried to avoid this by passing the MapView as a prop to the component doing the animation. My idea was that since the prop is not be changed, the MapView shouldn't be re-instantiated. Unfortunately this doesn't help..
I also tried wrapping the MapView in another component and having shouldComponentUpdate always returning false. Doesn't help either..
Is there someway I can prevent the MapView from re-initializing when I move it in the render tree?
My render tree looks like this:
var map = <MapView />;
When map in ScrollView:
<ScrollView>
...some other content...
{map}
</ScrollView>
when in Overlay:
<ScrollView>
...some other content..
<Overlay isVisible={true} aboveStatusBar={true}>
<View style={styles.fullScreen}>
<Animated.View style={[styles.mapContainer,{top: this.state.topValue, height: this.state.heightValue}]}>
{map}
</Animated.View>
</View>
</Overlay>
</ScrollView>
I believe you should add key property to the Map component. This is the only way to tell React that the particular components in two rendering passes are the same component in fact, so it will reorder the component rather than destroy/recreate. Without key, if the component moves in the tree, react will always destroy/recreate it as it does not know that it's actually the same component (there is nothing that could tell react it is). The key property works in lists/arrays but I think it should also work for more complex tree rearrangements.
See more details here: https://facebook.github.io/react/docs/multiple-components.html#dynamic-children
Note that the link above is for react.js not react-native, but I believe it should work in exactly the same way. I found that there are quite many concepts/details not explained in react-native tutorial, but they are clear in the react.js one (for example explanation about ref property). Actually the authors assume that you have experience with react (so I went on and learned React.js as well ;):
From https://facebook.github.io/react-native/docs/tutorial.html#content :
We assume you have experience writing websites with React. If not,
you can learn about it on the React website.

Resources