{"id":23078067,"url":"https://github.com/insanj/react-native-core-haptics-api","last_synced_at":"2025-08-15T19:33:15.712Z","repository":{"id":52823909,"uuid":"356757871","full_name":"insanj/react-native-core-haptics-api","owner":"insanj","description":"✋  React Native → iOS Core Haptics","archived":false,"fork":false,"pushed_at":"2023-07-07T22:43:57.000Z","size":617,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-12-12T07:20:00.983Z","etag":null,"topics":["haptics","react-native"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-core-haptics-api","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/insanj.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}},"created_at":"2021-04-11T03:33:33.000Z","updated_at":"2023-12-26T18:21:06.000Z","dependencies_parsed_at":"2022-08-23T07:41:18.605Z","dependency_job_id":null,"html_url":"https://github.com/insanj/react-native-core-haptics-api","commit_stats":null,"previous_names":["snowcodedesign/react-native-core-haptics-api"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insanj%2Freact-native-core-haptics-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insanj%2Freact-native-core-haptics-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insanj%2Freact-native-core-haptics-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insanj%2Freact-native-core-haptics-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/insanj","download_url":"https://codeload.github.com/insanj/react-native-core-haptics-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229948944,"owners_count":18149571,"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":["haptics","react-native"],"created_at":"2024-12-16T10:46:23.942Z","updated_at":"2024-12-16T10:46:25.173Z","avatar_url":"https://github.com/insanj.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](rn_ch.png)\n\n# react-native-core-haptics-api\n\n✋ React Native → iOS Core Haptics\n\n## About\n\nreact-native-core-haptics-api is a lightweight iOS-only module designed to expose the following Core Haptics methods to React Native:\n\n- `-capabilitiesForHardware`\n- `-stop`\n- `-makePlayer`\n- `-start`\n\nThis requires surfacing the following interfaces:\n\n- `HapticDeviceCapabilty`\n- `HapticEventParameterID`\n- `HapticEventParameter`\n- `HapticEventEventType`\n- `HapticEvent`\n- `HapticPattern`\n\nWhich provide JSON representations of all required iOS objects. All functionality is funneled through the central type:\n\n- `HapticEngine`\n\nThese features are made available using syntax and patterns that resemble the native Swift implementation as closely as possible. This means largely remodeling the flow to use a singleton-based structure with TypeScript interfaces, and thus no direct handoff of native objects (which is not supported in React Native modules as of today).\n\nNo other functionality is planned for this library, although feature parity with iOS Core Haptics is technically possible.\n\nRead more about [Core Haptics on the Apple Developer site](https://developer.apple.com/documentation/corehaptics).\n\n## Install\n\n```sh\nyarn add react-native-core-haptics-api\n```\n\nor\n\n```sh\nnpm install react-native-core-haptics-api\n```\n\n## Usage\n\n```js\n// import the needed classes at the top of the file\nimport { HapticEngine, \n  HapticPatternType, \n  HapticEventType,\n  HapticEventParameterType,\n  HapticEventParameterIDType,\n  HapticEventEventTypeType,\n  HapticDeviceCapabilityType\n} from 'react-native-core-haptics-api';\n\n// this is copy \u0026 paste from ./example/src/App.tsx\nconst playExampleHapticPattern = async () =\u003e {\n    // before running, it's a good idea to check if the device supports haptics\n    const capabilities = await HapticEngine.getDeviceCapabilities() as HapticDeviceCapabilityType;\n    if (!capabilities.supportsHaptics) {\n        throw new Error(\"Device does not support haptics :(\");\n    }\n\n    // build the patterns that the HapticEngine has to play\n    const hapticEvent = {} as HapticEventType;\n\n    // the first two properties are simple number (TimeInterval) value\n    hapticEvent.duration = 0.5;\n    hapticEvent.relativeTime = 0;\n\n    // now, let's provide the eventType, a tiny JSON object with a string underlying value. we wrap this object in order to support enum checking (and other features) in the future.\n    const eventType: HapticEventEventTypeType = {\n        rawValue: \"HapticContinuous\"\n    };\n\n    hapticEvent.eventType = eventType;\n\n    // next, we provide the parameters (i.e. keyframes) for this pattern, each a float-pointing value with an identifier to associate that value with the proper Haptic config option\n    const parameters: HapticEventParameterType[] = [];\n\n    const intensityParameterID: HapticEventParameterIDType = {\n        rawValue: \"HapticIntensity\"\n    };\n\n    const intensityParameter: HapticEventParameterType = {\n        parameterID: intensityParameterID,\n        value: 1\n    };\n\n    parameters.push(intensityParameter);\n\n    const sharpnessParameterID: HapticEventParameterIDType = {\n        rawValue: \"HapticSharpness\"\n    };\n\n    const sharpnessParameter: HapticEventParameterType = {\n        parameterID: sharpnessParameterID,\n        value: 0.6\n    };\n\n    parameters.push(sharpnessParameter);\n\n    hapticEvent.parameters = parameters;\n\n    // okay, now we've fully assembled our \"event\" object, which we can now send through to the CoreHaptics API\n    // this should match the following layout:\n    // const event = {\n    //     parameters: [{\n    //         parameterID: {\n    //             rawValue: \"HapticIntensity\"\n    //         },\n    //         value: 1,\n    //     }, {\n    //         parameterID: {\n    //             \"HapticSharpness\",\n    //         },\n    //         value: 0.6\n    //     }],\n    //     eventType: {\n    //         rawValue: \"HapticContinuous\",\n    //     },\n    //     duration: 0.5,\n    //     relativeTime: 0\n    // };\n\n    // and we can pull multiple events into a complex pattern like so\n    const hapticEvents: HapticEventType[] = [\n        hapticEvent\n    ];\n\n    const pattern: HapticPatternType = {\n        hapticEvents\n    };\n\n    // when we're ready to play, we must first start the HapticEngine (if it has never been started before). we can provide a UUID instead of null if we need more than one HapticEngine.\n    await HapticEngine.start(undefined);\n\n    // now, we create a player for this specific pattern (which is cached based on the setup of the pattern)\n    await HapticEngine.makePlayer(pattern, undefined);\n\n    // play time! finds the player and engine in memory based on UUID and pattern data\n    const startTime = 0;\n    await HapticEngine.startPlayerAtTime(pattern, startTime, undefined);\n\n    setTimeout(() =\u003e {\n      // and when we're ready to stop, we can do\n      HapticEngine.stop(undefined)\n        .then(() =\u003e {\n            // yay happy path :)\n        })\n        .catch(stopError =\u003e {\n          console.error(stopError);\n        })\n    }, 1000);\n  }\n}\n```\n\n## Authors\n\n```\nJulian Weiss\nsnowcode.design\n(c) 2021 Julian Weiss \u0026 Gamebytes\n```\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2021 Julian Weiss \u0026 Gamebytes\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsanj%2Freact-native-core-haptics-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsanj%2Freact-native-core-haptics-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsanj%2Freact-native-core-haptics-api/lists"}