forked from pmndrs/react-three-flex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING: allow to pass an outer yoga provider
This is mainly to allow usage of yoga-layout-wasm. From now on there's 2 entrpoints, a default one with YogaPrebuiltProvider (which uses yoga-layout-prebuilt) and outerRuntime that exports YogaProvider that allows to pass an arbitrary runtime (that conforms with Yoga types) This is a breaking change because library users will have to place a YogaProvider/YogaPrebuiltProvider in their code Fixes pmndrs#66
- Loading branch information
1 parent
4c7e23f
commit 08c64fa
Showing
25 changed files
with
980 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
const { override, addWebpackAlias, addWebpackPlugin } = require('customize-cra') | ||
const { override, addWebpackAlias, addWebpackPlugin, } = require('customize-cra') | ||
const { addReactRefresh } = require('customize-cra-react-refresh') | ||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin | ||
const path = require('path') | ||
|
||
module.exports = override( | ||
addReactRefresh(), | ||
addWebpackAlias({ | ||
// addReactRefresh(), | ||
// addWebpackAlias({ | ||
// three$: path.resolve('./src/utils/three.js'), | ||
// '../../../build/three.module.js': path.resolve('./src/utils/three.js'), | ||
}), | ||
// '@react-three/flex': path.resolve('../'), | ||
// }) | ||
//addWebpackPlugin(new BundleAnalyzerPlugin()) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { createContext, PropsWithChildren, useCallback, useContext, useMemo } from 'react' | ||
import { useAsset } from 'use-asset' | ||
// eslint-disable-next-line import/no-unresolved | ||
import Yoga from 'yoga-layout' | ||
|
||
interface YogaContextData { | ||
initYoga: () => Promise<typeof Yoga> | ||
} | ||
|
||
const YogaContext = createContext<YogaContextData>({ | ||
initYoga() { | ||
return Promise.reject(new Error("YogaRuntimeProvider hasn't been initialized")) | ||
}, | ||
}) | ||
|
||
export const YogaProvider = ({ initYoga, ...props }: PropsWithChildren<YogaContextData>) => { | ||
const value = useMemo(() => ({ initYoga }), [initYoga]) | ||
return <YogaContext.Provider value={value} {...props} /> | ||
} | ||
|
||
export const useYoga = (): typeof Yoga => { | ||
const { initYoga } = useContext(YogaContext) | ||
const yoga = useAsset(initYoga) | ||
return yoga | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { PropsWithChildren, useCallback } from 'react' | ||
import Yoga from 'yoga-layout-prebuilt' | ||
import { YogaProvider } from './YogaProvider' | ||
|
||
export * from './Box' | ||
export * from './Flex' | ||
export * from './props' | ||
export * from './hooks' | ||
export type { Axis } from './util' | ||
|
||
export const YogaPrebuiltProvider = (props: PropsWithChildren<{}>) => { | ||
const initYoga = useCallback(() => Promise.resolve(Yoga), []) | ||
return <YogaProvider initYoga={initYoga} {...props} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "examples2", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"serve": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@react-three/fiber": "^7.0.7", | ||
"@react-three/flex": "^0.7.0", | ||
"react": "^17.0.0", | ||
"react-dom": "^17.0.0", | ||
"yoga-layout-wasm": "^1.9.3-alpha.7" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@vitejs/plugin-react": "^1.0.0", | ||
"typescript": "^4.3.2", | ||
"vite": "^2.5.4" | ||
} | ||
} |
Oops, something went wrong.