Capture motion in React Native apps
Forward shakes and accelerometer samples already observed by a React Native app into its Ansight session.
Motion capture is opt-in on iOS and Android. The @ansight/react-native package exposes the native motion capture API; it does not create a sensor listener or request motion permissions. Use your app’s existing native or JavaScript motion source.
Enable capture
Add withMotionCapture() to the options used in your development-build bootstrap:
import Ansight from "@ansight/react-native";
const options = Ansight.createOptionsBuilder()
.withAnsightDefaults()
.withMotionCapture()
.build();
await Ansight.initializeAndActivate(options);
Keep initialization in the guarded app startup path described in React Native Setup, rather than a screen that can mount repeatedly.
Forward observations
Call these methods from handlers your app already owns:
await Ansight.recordShake();
await Ansight.recordAccelerometer(x, y, z); // m/s²
Android accelerometer samples are already in metres per second squared. Convert Apple accelerometer values from g by multiplying each axis by 9.80665 before forwarding. The bridge forwards to the active native runtime; it does not begin sampling on its own.
The default option includes shakes and accelerometer samples. withMotionCapture({ captureShake, captureAccelerometer, minimumSampleIntervalMilliseconds }) can narrow capture or change the sample interval. The interval defaults to 20 ms and is clamped to 10–1000 ms.
The host stores app-observed motion in motion/events.json and the session’s motion timeline. For host-injected device motion and the shared evidence contract, see Motion Capture.