question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use react-three-fiber with React Native

See original GitHub issue

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

    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
    npx create-react-native-app my-app -t with-react-three-fiber
    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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
polymorphercommented, Feb 15, 2021

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 😃

4reactions
haydenlindercommented, Nov 10, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation - React Three Fiber documentation
Fiber is compatible with React v18.0.0+ and works with ReactDOM and React Native. Getting started with React Three Fiber is not nearly as...
Read more >
reactjs - Can't get react-three/fiber to render a canvas in my ...
MyCanvas is a class component since it extends React.Component . In your case, I guess what you want is this:
Read more >
@react-three/fiber - npm
A React renderer for Threejs. Latest version: 8.9.1, last published: 2 months ago. Start using @react-three/fiber in your project by running ...
Read more >
Trying to use react three fiber and it doesn't install - Reddit
It looks like the react version in your project isn't compatible with the version of react-three-fiber. Try installing a different version of ...
Read more >
I wish I knew this before using React Three Fiber - YouTube
Sometimes the best way to understand a library like React Three Fiber is to compare it to the original 3D web library, Three....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found