diff --git a/with-react-three-fiber/App.js b/with-react-three-fiber/App.js new file mode 100644 index 0000000..e8e782e --- /dev/null +++ b/with-react-three-fiber/App.js @@ -0,0 +1,56 @@ +import React, { useRef, useState } from "react"; +import { StyleSheet, View } from "react-native"; +import { Canvas, useFrame } from "react-three-fiber"; + +function Box(props) { + // This reference will give us direct access to the mesh + const mesh = useRef(); + + // Set up state for the hovered and active state + const [hovered, setHover] = useState(false); + const [active, setActive] = useState(false); + + // Rotate mesh every frame, this is outside of React without overhead + useFrame(() => { + if (mesh && mesh.current) { + mesh.current.rotation.x = mesh.current.rotation.y += 0.01; + } + }); + + return ( + setActive(!active)} + onPointerOver={(e) => setHover(true)} + onPointerOut={(e) => setHover(false)} + > + + + + ); +} + +export default function App() { + return ( + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: "black", + }, +}); diff --git a/with-react-three-fiber/README.md b/with-react-three-fiber/README.md new file mode 100644 index 0000000..dbddd01 --- /dev/null +++ b/with-react-three-fiber/README.md @@ -0,0 +1,25 @@ +# React Three Fiber Example + +

+ + Supports Expo iOS + + Supports Expo Android + + Supports Expo Web +

+ +Create Three.js projects using React components and props! + +## 🚀 How to use + +> `npx create-react-native-app my-app -t with-react-three-fiber` + +- Run `yarn` or `npm install` +- Run [`expo start`](https://docs.expo.io/versions/latest/workflow/expo-cli/), try it out. + +## 📝 Notes + +- [react-three-fiber docs](https://github.com/react-spring/react-three-fiber) +- [three.js docs](https://threejs.org/docs/) +- [expo-three docs](https://github.com/expo/expo-three) diff --git a/with-react-three-fiber/babel.config.js b/with-react-three-fiber/babel.config.js new file mode 100644 index 0000000..2900afe --- /dev/null +++ b/with-react-three-fiber/babel.config.js @@ -0,0 +1,6 @@ +module.exports = function(api) { + api.cache(true); + return { + presets: ['babel-preset-expo'], + }; +}; diff --git a/with-react-three-fiber/package.json b/with-react-three-fiber/package.json new file mode 100644 index 0000000..2ad254d --- /dev/null +++ b/with-react-three-fiber/package.json @@ -0,0 +1,16 @@ +{ + "dependencies": { + "expo": "37.0.7", + "expo-gl": "8.2.0", + "expo-three": "5.4.0", + "react": "16.9.0", + "react-dom": "16.9.0", + "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz", + "react-native-web": "0.11.7", + "react-three-fiber": "^4.2.8", + "three": "^0.117.1" + }, + "devDependencies": { + "@babel/core": "7.9.0" + } +}