react-three-fiber: Unable to use react-three-fiber with React Native
Hi there.
First of all, thank you for creating this project. I like it a lot!
I am trying to use r3f it to create an app with React Native that will at least work on iOS.
I have tried using the setup prescribed
- here https://github.com/pmndrs/react-three-fiber/blob/master/recipes.md#usage-with-react-native,
- Bootstrap (hangs on ‘Loading project files’)
npx create-react-native-app -t with-react-three-fiber
-
- Manual Setup (works in browser but shows blank page on physical iOS)
# Install the Expo CLI
npm i -g expo-cli
# Create a new project
expo init myapp
cd myapp
# Install packages
yarn add expo-gl expo-three three@latest react-three-fiber@beta
# Start the project
yarn start
- here https://github.com/expo/examples/tree/master/with-react-three-fiber#-how-to-use (hangs on ‘Locating project files’)
npx create-react-native-app my-app -t with-react-three-fiber
- and here https://github.com/expo/expo-three#quick-start (same as above)
npx create-react-native-app -t with-react-three-fiber
Here’s the code I have in App.js
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { Canvas } from 'react-three-fiber';
import { StyleSheet, Text, SafeAreaView } from 'react-native';
export default function App() {
return (
<SafeAreaView style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Canvas>
<ambientLight/>
<mesh>
<boxBufferGeometry args={[1,1,1]}/>
<meshPhysicalMaterial color='blue'/>
</mesh>
</Canvas>
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
I have also tried downloading this repo https://github.com/birkir/react-three-fiber-examples, which throws an error even after installing dependencies.
The README of r3f claims that react-three-fiber can be used with React Native but you mention in other issues that you are not familiar with React Native and there is currently no working downloadable demo for React Native.
Could you please provide a React Native demo that works on iOS/Android or remove the statement that the library can be used with React Native? Otherwise it is very confusing.
Please let me know if there’s more info I can provide that would help.
Thanks!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
I got my react-native (iOS) project to work and we didn’t need to wrap Canvas with WebView. It took a lot of debugging to figure things out, but more on how it works, not to fix anything. The authors of react-three-fiber really did a great job for multi-platform support. I would be happy to write a doc or two when our project slows down and I get a bit of free time 😃
I was able to get it working! Here is a very simple working snack - https://snack.expo.io/@haydenlinder/react-native-&-react-three-fiber
Feel free to reference it in the docs.
However, it seems that there is still not a good way to load 3D models (glb, gltf) across platforms. See this related issue https://github.com/expo/expo-three/issues/182
I wish I knew where to start but I am new to mobile development myself. If you have any ideas I’d love to hear them.
We just launched a beta of fiber alongside react@beta including full react-native support (events, loaders, imperative render API, etc.). Install instructions here – nothing special for expo/bare apps.
I’d like to add docs more specific to react-native, as there are some pitfalls when working with three. Generally, as long as your models are packed, loaders won’t try to fetch images that don’t exist along an absolute path. DRACO I’m not sure we can support. We don’t polyfill anything, but maybe we should.
I sent over a PR to update the expo example, but that repo seems inactive. In the meantime, you can find installation instructions on https://docs.pmnd.rs/react-three-fiber/getting-started/installation. I’ll be working on adding react-native tutorials and examples as we streamline the docs site.
Closing now that native support is stable and released with v8 beta.
@iWhacko Can you post some code on a sandbox? I can take a look. Also make sure you are not loading a model with texture. See https://github.com/expo/expo-three/issues/144. It took me a while to get it working so it’s a bit hard to describe that step-by-step. I was thinking of writing a tutorial / guide later after I wrap up a few projects.
@polymorpher I’m having trouble running native on iOS aswell, could you perhaps share your steps? I get blank screen, while my scene works fine in WEB.
To summarise for anyone wanting to pick this up, the
react-native
docs could do with some love & probably regular upkeep since it changes to so much.