{"id":23305954,"url":"https://github.com/kingstinct/react-native-motion-activity-tracker","last_synced_at":"2025-09-01T12:11:28.837Z","repository":{"id":264193287,"uuid":"888950097","full_name":"kingstinct/react-native-motion-activity-tracker","owner":"kingstinct","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-17T16:53:44.000Z","size":26866,"stargazers_count":5,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-28T06:29:49.546Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/kingstinct.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2024-11-15T10:12:57.000Z","updated_at":"2025-03-04T18:01:13.000Z","dependencies_parsed_at":"2024-11-22T15:37:03.467Z","dependency_job_id":null,"html_url":"https://github.com/kingstinct/react-native-motion-activity-tracker","commit_stats":null,"previous_names":["kingstinct/react-native-motion-activity-tracker"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kingstinct/react-native-motion-activity-tracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingstinct%2Freact-native-motion-activity-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingstinct%2Freact-native-motion-activity-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingstinct%2Freact-native-motion-activity-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingstinct%2Freact-native-motion-activity-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingstinct","download_url":"https://codeload.github.com/kingstinct/react-native-motion-activity-tracker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingstinct%2Freact-native-motion-activity-tracker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273122129,"owners_count":25049539,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-20T12:14:54.806Z","updated_at":"2025-09-01T12:11:28.805Z","avatar_url":"https://github.com/kingstinct.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-motion-activity-tracker\n\n[![Test Status](https://github.com/Kingstinct/react-native-motion-activity-tracker/actions/workflows/test.yml/badge.svg)](https://github.com/Kingstinct/react-native-motion-activity-tracker/actions/workflows/test.yml)\n[![Latest version on NPM](https://img.shields.io/npm/v/react-native-motion-activity-tracker)](https://www.npmjs.com/package/react-native-motion-activity-tracker)\n[![Discord](https://dcbadge.vercel.app/api/server/5wQGsRfS?style=flat)](https://discord.gg/5wQGsRfS)\n\n\nA React Native library to access and track motion activity data using Apple's Core Motion API. It supports activities like walking, running, automotive, stationary, and cycling, with real-time updates and historical data fetching.\n\n## Features\n\n- Check motion activity authorization status.\n- Start and stop real-time motion tracking.\n- Fetch historical activity data.\n- Built for iOS  with Core Motion API \u0026 for android with Activity Recognition API\n\n**Note**: This library requires a custom dev client when using with Expo.\n\n# React Native Motion Activity Tracker\n\n## Managed Expo Workflow\n\n### Installation\n\n1. Install the package:\n\n   ```bash\n   npm install react-native-motion-activity-tracker\n\n```\n2. Add this to ur app.son\n\n{\n  \"expo\": {\n    \"plugins\": [\n      \"react-native-motion-activity-tracker\"\n    ]\n  }\n}\n\n```\n3. If you want to customize the iOS permission description, you can configure it like this:\n {\n  \"expo\": {\n    \"plugins\": [\n      [\n        \"react-native-motion-activity-tracker\",\n        {\n          \"NSMotionUsageDescription\": \"This app uses motion data to enhance your experience.\"\n        }\n      ]\n    ]\n  }\n}\n\n4. After making these changes, rebuild your app to apply the native changes:\n  \n   ```bash\n   expo prebuild\n   ```\n\n\n\n# Examples\n\n```TypeScript\nimport * as MotionActivityTracker from \"motion-activity-tracker\";\nimport React, { useEffect, useState } from \"react\";\nimport { Text, View, Button, StyleSheet } from \"react-native\";\n\nexport default function App() {\n  const [message, setMessage] = useState(\"Initializing...\");\n  const [tracking, setTracking] = useState(false);\n  const [data, setData] = useState\u003c\n    MotionActivityTracker.HistoricalActivity[] | undefined\n  \u003e();\n  const startDate = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); // One week ago\n  const endDate = new Date();\n\n  // Fetch historical activity data\n  useEffect(() =\u003e {\n    const setActivityHistoricalData = async () =\u003e {\n      const data = await MotionActivityTracker.getHistoricalData(\n        startDate,\n        endDate,\n      );\n      if (data) {\n        console.log(data[0]);\n        setData(data);\n      }\n    };\n    setActivityHistoricalData();\n  }, []);\n\n  // Subscribe to motion state changes\n  useEffect(() =\u003e {\n    const subscription = MotionActivityTracker.addMotionStateChangeListener(\n      (event) =\u003e {\n        console.log(\"New Motion State:\", event.state); // Log the new state\n        setMessage(`Tracking started: ${event.state}`); // Update the message\n      },\n    );\n\n    return () =\u003e {\n      subscription.remove(); // Clean up subscription on unmount\n    };\n  }, [message]);\n\n  const handleStartTracking = async () =\u003e {\n    try {\n      const result = await MotionActivityTracker.startTracking();\n      setMessage(`Tracking started: ${result}`);\n      setTracking(true);\n    } catch (error) {\n      setMessage(`Error: ${error}`);\n      console.error(error);\n    }\n  };\n\n  const handleStopTracking = () =\u003e {\n    MotionActivityTracker.stopTracking();\n    setMessage(\"Tracking stopped\");\n    setTracking(false);\n  };\n\n  return (\n    \u003cView style={styles.container}\u003e\n      \u003cText style={styles.text}\u003e{message}\u003c/Text\u003e\n      \u003cButton\n        title={tracking ? \"Stop Tracking\" : \"Start Tracking\"}\n        onPress={tracking ? handleStopTracking : handleStartTracking}\n      /\u003e\n      {data \u0026\u0026 data.length \u003e 0 \u0026\u0026 (\n        \u003cView\u003e\n          {/* Display the latest entry */}\n          {(() =\u003e {\n            const latestActivity = data.reduce((latest, current) =\u003e\n              current.timestamp \u003e latest.timestamp ? current : latest,\n            );\n\n            return (\n              \u003c\u003e\n                \u003cText style={styles.text}\u003e\n                  Automotive: {latestActivity.automotive ? \"Yes\" : \"No\"}\n                \u003c/Text\u003e\n                \u003cText style={styles.text}\u003e\n                  Running: {latestActivity.running ? \"Yes\" : \"No\"}\n                \u003c/Text\u003e\n                \u003cText style={styles.text}\u003e\n                  Stationary: {latestActivity.stationary ? \"Yes\" : \"No\"}\n                \u003c/Text\u003e\n                \u003cText style={styles.text}\u003e\n                  Timestamp: {new Date(latestActivity.timestamp * 1000).toLocaleString()}\n                \u003c/Text\u003e\n                \u003cText style={styles.text}\u003e\n                  Unknown: {latestActivity.unknown ? \"Yes\" : \"No\"}\n                \u003c/Text\u003e\n                \u003cText style={styles.text}\u003e\n                  Walking: {latestActivity.walking ? \"Yes\" : \"No\"}\n                \u003c/Text\u003e\n                \u003cText style={styles.text}\u003e\n                  Confidence: {latestActivity.confidence}\n                \u003c/Text\u003e\n              \u003c/\u003e\n            );\n          })()}\n        \u003c/View\u003e\n      )}\n    \u003c/View\u003e\n  );\n}\n\n\n```\n\n\n# Bare React Native Workflow\nFor bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.\n\n### Add the package to your npm dependencies\n\n```\nnpm install react-native-device-activity\n```\n#### Add permissions for Motion \u0026 Fitness tracking in your Info.plist:\n\n```\n\u003ckey\u003eNSMotionUsageDescription\u003c/key\u003e\n\u003cstring\u003eThis app uses motion data to track your activity.\u003c/string\u003e\n```\n\n### Configure for iOS\n\nRun `npx pod-install` after installing the npm package.\n\n\n\n\n## API Reference\n\n### `startTracking(): Promise\u003cTrackingStatus\u003e`\nStarts real-time tracking of motion activity. Returns a promise that resolves to the initial motion state.\n\n### `stopTracking(): Promise\u003cTrackingStatus\u003e`\nStops the real-time motion tracking.\n\n### `addMotionStateChangeListener(listener: (event: EventPayload) =\u003e void): Subscription`\nAdds a listener to receive updates when the motion state changes.\n\n### `getHistoricalData(startDate: Date, endDate: Date): Promise\u003cHistoricalActivity[]\u003e`\nFetches historical activity data for the given date range.\n\n### `getPermissionStatusAsync(): Promise\u003cPermissionStatus\u003e`\nChecks the current motion activity permission status for iOS.\n\n### `requestPermissionsAsyncAndroid(): Promise\u003cPermissionStatus\u003e`\nRequests motion activity permissions for Android devices.\n\n### `isGooglePlayServicesAvailable: boolean`\nIndicates whether Google Play Services are available on the current Android device.\n\n### `checkMotionActivityAuthStatus(): Promise\u003cMotionActivityAuthStatus\u003e`\nChecks the motion activity authorization status. Returns one of the following statuses:\n\n- `NOT_DETERMINED`\n- `RESTRICTED`\n- `DENIED`\n- `AUTHORIZED`\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome!\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingstinct%2Freact-native-motion-activity-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingstinct%2Freact-native-motion-activity-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingstinct%2Freact-native-motion-activity-tracker/lists"}