{"id":25127643,"url":"https://github.com/lasjdhu/motion-event","last_synced_at":"2025-04-02T20:44:59.697Z","repository":{"id":275652250,"uuid":"926755227","full_name":"lasjdhu/motion-event","owner":"lasjdhu","description":"Lightweight and efficient Expo module for handling raw motion events on Android","archived":false,"fork":false,"pushed_at":"2025-02-23T23:42:00.000Z","size":9410,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T15:17:00.864Z","etag":null,"topics":["events","expo","expo-module","motion-event","pointer","react-native","touch"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/motion-event","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lasjdhu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-03T20:00:04.000Z","updated_at":"2025-03-02T19:22:16.000Z","dependencies_parsed_at":"2025-02-03T21:22:43.419Z","dependency_job_id":"b41e276f-ef99-4369-b099-12a02ebedab4","html_url":"https://github.com/lasjdhu/motion-event","commit_stats":null,"previous_names":["lasjdhu/motion-event"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lasjdhu%2Fmotion-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lasjdhu%2Fmotion-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lasjdhu%2Fmotion-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lasjdhu%2Fmotion-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lasjdhu","download_url":"https://codeload.github.com/lasjdhu/motion-event/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246892778,"owners_count":20850845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["events","expo","expo-module","motion-event","pointer","react-native","touch"],"created_at":"2025-02-08T11:17:38.493Z","updated_at":"2025-04-02T20:44:59.692Z","avatar_url":"https://github.com/lasjdhu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# motion-event [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)\n\n`v0.1.0`\n\nLightweight and efficient Expo module for handling raw motion events on Android\n\n## 🚀 Features\n\n- **Direct access** to Android `MotionEvent` API\n- **High-performance event tracking** with minimal overhead\n- **Customizable FPS target** to balance responsiveness and performance\n- **Multiple touch points support**\n- **Expo-compatible**, making integration seamless in managed and bare workflows\n- Start and stop listening with built-in functions\n\n## Installation\n\n```sh\nnpm i motion-event\n```\n\n## 🎨 Preview\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Example\" src=\"readme-assets/example.gif\" width=\"250\"/\u003e\n\u003c/p\u003e\n\n## 💻 Basic Usage\n\nYou can see the working example in the `example` directory.\n\n```tsx\nexport default function App() {\n  const [event, setEvent] = useState\u003cMotionEvent | null\u003e(null);\n  const [fps, setFps] = useState(60);\n\n  useEffect(() =\u003e {\n    startListening();\n    setTargetFPS(fps);\n\n    const subscription = addMotionEventListener((motionEvent) =\u003e {\n      setEvent(motionEvent);\n    });\n\n    return () =\u003e {\n      subscription.remove();\n      stopListening();\n    };\n  }, [fps]);\n\n  return (\n    \u003cSafeAreaView\u003e\n      \u003cView\u003e\n        \u003cPressable onPress={() =\u003e startListening()}\u003e\n          \u003cText\u003eStart\u003c/Text\u003e\n        \u003c/Pressable\u003e\n        \u003cPressable onPress={() =\u003e stopListening()}\u003e\n          \u003cText\u003eStop\u003c/Text\u003e\n        \u003c/Pressable\u003e\n        \u003cTextInput value={fps} onChangeText={(e) =\u003e setFps(Number(e))} /\u003e\n      \u003c/View\u003e\n\n      \u003cText\u003e{JSON.stringify(event, null, 2)}\u003c/Text\u003e\n    \u003c/SafeAreaView\u003e\n  );\n}\n```\n\n## 🤔 Alternatives\n\n| Library                                                                                          | Focus                       |\n| ------------------------------------------------------------------------------------------------ | --------------------------- |\n| [react-native-gesture-handler](https://github.com/software-mansion/react-native-gesture-handler) | Gesture-based interactions  |\n| [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated)           | Advanced gesture animations |\n\nUnlike gesture-based libraries, `motion-event` is designed for low-level event handling, making it ideal for use cases requiring precise touch tracking, such as custom multi-touch interactions and real-time input processing.\n\n## API Reference\n\n### Functions\n\n#### `startListening()`\n\nStarts listening for motion events.\n\n```typescript\nfunction startListening(): void;\n```\n\n#### `stopListening()`\n\nStops listening for motion events.\n\n```typescript\nfunction stopListening(): void;\n```\n\n#### `setTargetFPS(fps: number)`\n\nSets the target frames per second for motion event updates.\n\n```typescript\nfunction setTargetFPS(fps: number): void;\n```\n\n#### `addMotionEventListener(listener: MotionEventListener)`\n\nAdds a listener for motion events. Returns an EventSubscription that can be used to remove the listener.\n\n```typescript\nfunction addMotionEventListener(\n  listener: MotionEventListener,\n): EventSubscription;\n```\n\n### Constants\n\n#### MotionEventActions\n\n```typescript\nconst MotionEventActions = {\n  DOWN: 0, // Touch down event\n  UP: 1, // Touch up event\n  MOVE: 2, // Touch move event\n  CANCEL: 3, // Touch cancel event\n  POINTER_DOWN: 5, // Additional pointer down\n  POINTER_UP: 6, // Additional pointer up\n} as const;\n```\n\n#### ToolTypes\n\n```typescript\nconst ToolTypes = {\n  FINGER: 1, // Touch input from finger\n  STYLUS: 2, // Input from stylus\n  MOUSE: 3, // Input from mouse\n  ERASER: 4, // Input from stylus eraser\n} as const;\n```\n\n### Types\n\n#### MotionEvent\n\nThe main event object containing all motion event data.\n\n```typescript\ninterface MotionEvent {\n  action: number; // The action type (see MotionEventActions)\n  actionMasked: number; // The masked action type\n  actionIndex: number; // Index of the pointer that triggered the event\n  eventTime: number; // Time the event occurred\n  downTime: number; // Time of the initial down event\n  edgeFlags: number; // Flags indicating which edges were touched\n  deviceId: number; // ID of the input device\n  source: number; // Source of the event\n  pointerCount: number; // Number of pointers in the event\n  pointerCoords: MotionEventCoords[]; // Array of pointer coordinates\n  pointerProperties: MotionEventProperties[]; // Array of pointer properties\n  rawX: number; // Raw X coordinate\n  rawY: number; // Raw Y coordinate\n  xPrecision: number; // X axis precision\n  yPrecision: number; // Y axis precision\n  velocityX: number; // X axis velocity\n  velocityY: number; // Y axis velocity\n  fps: number; // Current FPS\n}\n```\n\n#### MotionEventCoords\n\nDetailed coordinates and properties for each pointer.\n\n```typescript\ninterface MotionEventCoords {\n  orientation: number; // Orientation of the tool\n  pressure: number; // Pressure of the touch\n  size: number; // Size of the touch area\n  toolMajor: number; // Major axis of the tool\n  toolMinor: number; // Minor axis of the tool\n  touchMajor: number; // Major axis of the touch area\n  touchMinor: number; // Minor axis of the touch area\n  x: number; // X coordinate\n  y: number; // Y coordinate\n}\n```\n\n#### MotionEventProperties\n\nProperties for each pointer.\n\n```typescript\ninterface MotionEventProperties {\n  id: number; // Unique identifier for the pointer\n  toolType: number; // Type of tool (see ToolTypes)\n}\n```\n\n#### MotionEventError\n\nError object structure.\n\n```typescript\ninterface MotionEventError {\n  code: string;\n  message: string;\n  details?: any;\n}\n```\n\n#### MotionEventResult\n\nUnion type for successful and error results.\n\n```typescript\ntype MotionEventResult =\n  | { type: \"success\"; data: MotionEvent }\n  | { type: \"error\"; error: MotionEventError };\n```\n\n## Contributing\n\nYour contributions to `motion-event` are welcomed! This package is currently in **testing phase** and is being prepared for publishing on NPM. Initially, this package was created to meet my own specific needs, but contributions from the community are highly encouraged. Feel free to create issues for feature requests, bug reports, or any improvements you have in mind.\n\nIf you'd like to contribute code, please check out [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flasjdhu%2Fmotion-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flasjdhu%2Fmotion-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flasjdhu%2Fmotion-event/lists"}