useAnimatedSensor: learn availability before the first render

Author: pawicaoCreated Sep 22, 2026Updated Sep 23, 2026
LabelsMaintainer issueargent-cloud

Follow-up of #10662.

Goal

Find out whether useAnimatedSensor can know isAvailable on its first render, without the extra render that #10662 adds, and how to do it.

Before #10662

The hook kept its result in a ref. The effect registered the native sensor, learned availability from the return value of registerSensor (-1 means not available), and set isAvailable on a new object in the ref. Nothing told React to render again. A component that read isAvailable during render saw false on the first render on every device, and the correct value only after an unrelated render. The same happened after a change of sensorType or config.

After #10662

The hook keeps its result in useState. The effect registers the sensor and sets the new object as state, so the next render shows the correct isAvailable. This costs one extra render per registration, not per sensor event. The first render still shows false, because registration is a side effect and must stay in the effect.

How it could work

Availability of the motion sensors is a pure question the platform can answer at any time: SensorManager.getDefaultSensor(type) != null on Android, the CMMotionManager flags such as isAccelerometerAvailable on iOS. Today that check runs only inside native registerSensor. A read-only native query, for example isSensorAvailable(sensorType), would let the hook ask during render, memoized on the sensor type, and return the correct flag on the first render. The query has no side effect, so the Strict Mode double render is harmless.

Points to check:

  1. The binding goes through the whole stack: C++ ReanimatedModuleProxy, Android Kotlin and JNI, iOS, the JS proxy types, mock.ts, web JSReanimated, and tests.
  2. The iOS hinge sensor (#10651) cannot be known up front. UIKit reports "no hinge" only through the first update after the interaction is attached. That path keeps the later state update.
  3. The meaning of the first render changes for every consumer, from "not known yet" to "known". This needs a changelog entry.
  4. Whether unregister on the returned object should stay public, since the hook cleanup already calls it.

Source: software-mansion/react-native-reanimated