{"id":13998557,"url":"https://github.com/luokuning/usedeviceorientationmotion","last_synced_at":"2025-04-13T10:43:42.179Z","repository":{"id":38173414,"uuid":"400443434","full_name":"luokuning/usedeviceorientationmotion","owner":"luokuning","description":"Card like rotation Value built on top of device orientation event for react-native","archived":false,"fork":false,"pushed_at":"2023-03-06T09:23:18.000Z","size":3352,"stargazers_count":7,"open_issues_count":11,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T02:08:12.677Z","etag":null,"topics":["deviceorientation","motion","rotation"],"latest_commit_sha":null,"homepage":"","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/luokuning.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}},"created_at":"2021-08-27T08:36:17.000Z","updated_at":"2023-05-25T02:01:21.000Z","dependencies_parsed_at":"2024-01-15T19:44:58.456Z","dependency_job_id":"0a36d850-f50d-4878-baa9-03918b04bb10","html_url":"https://github.com/luokuning/usedeviceorientationmotion","commit_stats":{"total_commits":42,"total_committers":2,"mean_commits":21.0,"dds":0.04761904761904767,"last_synced_commit":"24ef3d3a57f415a526617233505d1e4a4772292b"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luokuning%2Fusedeviceorientationmotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luokuning%2Fusedeviceorientationmotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luokuning%2Fusedeviceorientationmotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luokuning%2Fusedeviceorientationmotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luokuning","download_url":"https://codeload.github.com/luokuning/usedeviceorientationmotion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248701997,"owners_count":21148111,"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":["deviceorientation","motion","rotation"],"created_at":"2024-08-09T19:01:46.735Z","updated_at":"2025-04-13T10:43:42.157Z","avatar_url":"https://github.com/luokuning.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003ch1 align=\"center\" style=\"border-bottom: none;\"\u003euseDeviceOrientationMotion\u003c/h1\u003e\n\u003ch3 align=\"center\"\u003eCard like rotation Value built on top of device orientation event for react-native\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"npm latest version\" src=\"https://img.shields.io/npm/v/usedeviceorientationmotion/latest.svg\" /\u003e\n  \u003cimg alt=\"travis build\" src=\"https://img.shields.io/travis/luokuning/usedeviceorientationmotion/main\" /\u003e\n  \u003cimg alt=\"RPs welcome\" src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\" /\u003e\n  \u003cimg alt=\"license\" src=\"https://img.shields.io/npm/l/usedeviceorientationmotion\" /\u003e\n  \u003cimg alt=\"codecov\" src=\"https://img.shields.io/codecov/c/github/luokuning/usedeviceorientationmotion\" /\u003e\n  \u003cimg alt=\"sementic-release\" src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\" /\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  \u003cimg src=\"https://github.com/luokuning/usedeviceorientationmotion/blob/main/assets/motion.gif?raw=true\" /\u003e\n\u003c/p\u003e\n\n`usedeviceorientationmotion` track device orientation event\nvia [react-native-sensors](https://github.com/react-native-sensors/react-native-sensors), and calculate the right\nrotation angle (`rotationX`, `rotationY`). It also leverages [three.js](https://github.com/mrdoob/three.js) to\navoid [gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock) problem.\n\n### Install\n\nInstall `usedeviceorientationmotion` and it's peer dependencies.\n\n```bash\nnpm i usedeviceorientationmotion react-native-sensors three\n# or\nyarn add usedeviceorientationmotion react-native-sensors three\n```\n\n### Usage\n\n```jsx\nimport useDeviceOrientationValue from 'usedeviceorientationmotion'\nimport { View, Image, Text, StyleSheet } from 'react-native'\nimport React from 'react'\nimport Card from '../../assets/images/address/img.jpg'\n\nconst App = () =\u003e {\n  const { rotation } = useDeviceOrientationValue({\n    limit: 12,\n    sensitivityX: 90,\n    sensitivityY: 45,\n  })\n  return (\n    \u003cView\n      style={[\n        styles.container,\n        {\n          transform: [\n            { perspective: 800 },\n            { rotateX: `${rotation.x}deg` },\n            { rotateY: `${rotation.y}deg` },\n          ],\n        },\n      ]}\u003e\n      \u003cImage source={Card} style={styles.cardImage} /\u003e\n      \u003cText\n        style={[\n          styles.title,\n          {\n            transform: [\n              { translateX: rotation.x * 0.3 },\n              { translateY: rotation.y * 0.3 },\n            ]\n          },\n        ]}\u003e\n        CREDIT CARD\n      \u003c/Text\u003e\n    \u003c/View\u003e\n  )\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    width: 300,\n    height: 200,\n    marginLeft: 35,\n    marginTop: 100,\n    shadowColor: '#000',\n    shadowOffset: {\n      width: 5,\n      height: 10,\n    },\n    shadowOpacity: 0.3,\n    shadowRadius: 10,\n  },\n  cardImage: {\n    width: 300,\n    height: 200,\n    borderRadius: 12,\n  },\n  title: {\n    fontSize: 30,\n    fontWeight: '900',\n    color: 'white',\n    position: 'absolute',\n    top: 70,\n    left: 60,\n  },\n})\n\nexport default App\n\n```\n\n### ⚠️ Caution\n\nRemember to add `{ perspective: 800 }` style for the element you want to animate.\n\n### Paramters\n\n| Key          | Type   | Default Value | Description                                     |\n|--------------|--------|---------------|-------------------------------------------------|\n| limit        | number | 15            | The maximum degree                              |\n| sensitivityX | number | 180           | The ratio that react to device motion in X axis |\n| sensitivityY | number | 90            | The ratio that react to device motion in Y axis |\n\n### Return\n\n```jsx\nconst { rotation, subscribe, unsubscribe } = useDeviceOrientationValue()\n```\n\n| Value       | Type                     | Desciption                           |\n|-------------|--------------------------|--------------------------------------|\n| rotation    | { x: number; y: number } | Rotation angle                       |\n| subscribe   | () =\u003e void               | Subscribe device orientation event   |\n| unsubscribe | () =\u003e void               | Unsubscribe device orientation event |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluokuning%2Fusedeviceorientationmotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluokuning%2Fusedeviceorientationmotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluokuning%2Fusedeviceorientationmotion/lists"}