munim-xr
v0.1.1
Published
Cross-platform XR sessions and native AR views for Expo and React Native, powered by Nitro Modules
Maintainers
Readme
Native ARKit and ARCore sessions for Expo and React Native, powered by Nitro Modules.
munim-xr provides a typed Nitro Hybrid View for world tracking, native camera rendering, plane detection, hit testing, anchors, camera poses, light estimation, optional depth, and snapshots on iOS and Android.
Install
npm install munim-xr react-native-nitro-modulesExpo projects can use:
npx expo install munim-xr react-native-nitro-modulesThen configure and rebuild the native app:
{
"expo": {
"plugins": [
[
"munim-xr",
{
"cameraPermission": "Allow $(PRODUCT_NAME) to use the camera for augmented reality.",
"arRequired": false
}
]
]
}
}npx expo prebuild
npx expo run:ios
# or: npx expo run:androidThis package requires React Native's New Architecture and a native development build. It cannot run in Expo Go.
Usage
import { useMemo, useRef } from 'react'
import { StyleSheet } from 'react-native'
import { callback } from 'react-native-nitro-modules'
import {
checkAvailability,
requestCameraPermission,
requestInstall,
XRView,
type XRViewRef,
} from 'munim-xr'
export function ARScene() {
const xrRef = useRef<XRViewRef | null>(null)
const hybridRef = useMemo(
() => callback((ref: XRViewRef) => (xrRef.current = ref)),
[]
)
async function start() {
if (!(await requestCameraPermission())) return
const availability = await checkAvailability()
if (availability === 'not-installed' || availability === 'update-required') {
if (!(await requestInstall())) return
}
await xrRef.current?.start()
}
return (
<XRView
depthEnabled={false}
frameCallbackFps={15}
hybridRef={hybridRef}
lightEstimationEnabled
planeDetection="both"
style={StyleSheet.absoluteFill}
/>
)
}Wrap hybridRef and event handlers with Nitro's callback(). The captured reference exposes start, pause, reset, hitTest, anchor management, camera pose, and snapshot methods.
const hits = await xrRef.current?.hitTest(0.5, 0.5)
if (hits?.[0]) {
const anchor = await xrRef.current?.createAnchor(hits[0].pose)
console.log(anchor?.id)
}Requirements
- React Native 0.78+ with the New Architecture
react-native-nitro-modules0.36.5+- iOS 15.1+ on an ARKit-capable device
- Android API 24+ with Google Play Services for AR
- Expo development build or bare React Native app
See the complete documentation for the platform matrix, API reference, runtime notes, and development instructions.
License
Apache-2.0
