React Native Blog Dec 13, 2022

Pointer Events Support in React Native

Article Summary

React Native just dropped experimental Pointer Events support, and it's a game-changer for cross-platform input handling. No more forking the framework to support mouse, pen, or keyboard interactions.

The React Native team is introducing a W3C-compliant Pointer Events API that unifies input handling across mobile, desktop, VR, and web. This addresses years of fragmentation where out-of-tree platforms had to fork React Native or build custom native modules just to support basic features like hover detection or left-click.

Key Takeaways

Critical Insight

React Native now offers a unified, standards-based API for handling all pointer input types across platforms, eliminating the need for platform-specific event handling code.

The implementation details reveal how they're leveraging Android's MotionEvent and iOS's UITouch under the hood, plus what's coming next for gesture handling APIs.

About This Article

Problem

React Native's touch event system couldn't handle hover detection, left-click, keyboard, and pen interactions across desktop, VR, and mobile platforms. This forced out-of-tree platforms to fork React Native or build custom native modules.

Solution

React Native adopted the W3C Pointer Events specification. It uses the existing MotionEvent and UITouch infrastructure on Android and iOS, mapping platform events into a unified pointer API through JSI and the React renderer's event queue.

Impact

The implementation now powers Meta's VR platform and Oculus Store in production. Seven core pointer events are implemented: onPointerOver, onPointerEnter, onPointerDown, onPointerMove, onPointerUp, onPointerOut, and onPointerLeave. These have been tested against ported Web Platform Tests for spec compliance.