Skip to content

Commit

Permalink
chore: add alphaTest to XrUi component
Browse files Browse the repository at this point in the history
  • Loading branch information
enijar committed Apr 3, 2023
1 parent af1836c commit 5cc6404
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-xr-ui",
"version": "0.0.48",
"version": "0.0.49",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
Expand Down
6 changes: 5 additions & 1 deletion src/components/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ function Layer(
return layerContext.renderOrder + zIndex + 1;
}, [layerContext.parentUuid, layerContext.renderOrder, zIndex]);

const alpha = React.useMemo(() => {
return xrUiContext.alphaTest ?? alphaTest;
}, [xrUiContext.alphaTest, alphaTest]);

const layerProviderValue = React.useMemo<LayerContextType>(() => {
return {
currentChildren,
Expand Down Expand Up @@ -547,7 +551,7 @@ function Layer(
transparent={true}
depthTest={depthTest}
depthWrite={depthWrite}
alphaTest={alphaTest}
alphaTest={alpha}
map={canvasTexture}
/>
</mesh>
Expand Down
11 changes: 7 additions & 4 deletions src/components/xr-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ export const XrUiContext = React.createContext<XrUiContextType>({
layerResolution: 1024,
fontFamily: "system-ui, sans-serif",
optimizedRendering: false,
alphaTest: 0,
});

type Props = {
children?: React.ReactNode;
layerResolution?: number;
fontFamily?: string;
optimizedRendering?: boolean;
layerResolution?: XrUiContextType["layerResolution"];
fontFamily?: XrUiContextType["fontFamily"];
optimizedRendering?: XrUiContextType["optimizedRendering"];
alphaTest?: XrUiContextType["alphaTest"];
};

export default function XrUi({
children,
layerResolution = 1024,
fontFamily,
optimizedRendering = false,
alphaTest,
}: Props) {
return (
<XrUiContext.Provider
value={{ layerResolution, fontFamily, optimizedRendering }}
value={{ layerResolution, fontFamily, optimizedRendering, alphaTest }}
>
{children}
</XrUiContext.Provider>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ export type XrUiContextType = {
layerResolution: number;
fontFamily: string;
optimizedRendering: boolean;
alphaTest: number;
};

0 comments on commit 5cc6404

Please sign in to comment.