UNPKG

@react-three/xr

Version:

VR/AR for react-three-fiber

39 lines (38 loc) 2.2 kB
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { useXR } from '../index.js'; function useIsInSessionMode(allow, deny) { const mode = useXR((state) => state.mode); if (deny != null) { return Array.isArray(deny) ? !deny.includes(mode) : deny != mode; } if (allow != null) { return Array.isArray(allow) ? allow.includes(mode) : allow === mode; } return mode !== null; } /** * Guard that only **shows** its children by toggling their visibility based on the current session mode. * If neither `allow` nor `deny` are provided, the visiblity will be based on whether or not any mode is currently being used. * * @param props * #### `children?` - `ReactNode` The ReactNode elements to conditionally show. * #### `allow?` - `XRSessionMode | ReadonlyArray<XRSessionMode | undefined>` The session mode(s) where the children will be shown. If not provided, the children will be shown in all modes except the ones in `deny`. * #### `deny?` - `XRSessionMode | ReadonlyArray<XRSessionMode | undefined>` The session mode(s) where the children will be hidden. */ export function ShowIfInSessionMode({ children, allow, deny }) { const visible = useIsInSessionMode(allow, deny); return _jsx("group", { visible: visible, children: children }); } /** * Guard that only **renders** its children to the scene based on the current session mode. * If neither `allow` nor `deny` are provided, the elements will be rendered based on whether or not any mode is currently being used. * * @param props * #### `children?` - `ReactNode` The ReactNode elements to conditionally render. * #### `allow?` - `XRSessionMode | ReadonlyArray<XRSessionMode | undefined>` The session mode(s) where the children will be rendered. If not provided, the children will be rendered in all modes except the ones in `deny`. * #### `deny?` - `XRSessionMode | ReadonlyArray<XRSessionMode | undefined>` The session mode(s) where the children will not be rendered. */ export function IfInSessionMode({ children, allow, deny }) { const visible = useIsInSessionMode(allow, deny); return visible ? _jsx(_Fragment, { children: children }) : null; }