|
3 | 3 | > Playing haptics can engage people's sense of touch and bring their familiarity with the physical world into your app or game.
|
4 | 4 | ~ Developer docs
|
5 | 5 |
|
6 |
| -For iOS and Android development. |
7 | 6 |
|
8 |
| -Thank you to [Eddy Verbruggen](EddyVerbruggen) for providing [nativescript-taptic-engine](https://github.com/EddyVerbruggen/nativescript-taptic-engine) as this continues it's evolution by streamlining the API and adding Android support, inspired by [react-native-haptic-feedback](https://github.com/junina-de/react-native-haptic-feedback). |
| 7 | +Thanks to [Eddy Verbruggen](EddyVerbruggen) for providing [nativescript-taptic-engine](https://github.com/EddyVerbruggen/nativescript-taptic-engine) as this continues its evolution by streamlining the API and adding Android support, inspired by [react-native-haptic-feedback](https://github.com/junina-de/react-native-haptic-feedback). |
9 | 8 |
|
10 |
| -## Usage |
| 9 | +## Table of Contents |
| 10 | + * [Installation](#installation) |
| 11 | + * [API](#api) |
| 12 | + * [isSupported()](#issupported) |
| 13 | + * [is6SAnd6SPlusSupported()](#is6sand6splussupported) |
| 14 | + * [selection()](#selection) |
| 15 | + * [notifcation()](#notification) |
| 16 | + * [impact()](#impact) |
| 17 | + * [HapticsFallback](#hapticsfallback) |
| 18 | + * [weakBoom()](#weakboom) |
| 19 | + * [strongBoom()](#strongboom) |
| 20 | + * [burst()](#burst) |
11 | 21 |
|
12 |
| -```javascript |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +```cli |
13 | 26 | npm install @nativescript/haptics
|
14 | 27 | ```
|
15 | 28 |
|
16 | 29 | ## API
|
17 | 30 |
|
18 |
| -### `selection` |
19 |
| -Use selection feedback generators to indicate a change in selection. |
| 31 | +### isSupported() |
| 32 | +```ts |
| 33 | +isHapticsSupported: boolean = Haptics.isSupported() |
| 34 | +``` |
| 35 | +Checks if Haptics is supported. |
20 | 36 |
|
21 |
| -##### TypeScript |
| 37 | +--- |
| 38 | +### is6SAnd6SPlusSupported() |
| 39 | +```ts |
| 40 | +isHapticsSupported: boolean = Haptics.is6SAnd6SPlusSupported() |
| 41 | +``` |
22 | 42 |
|
23 |
| -```js |
24 |
| -import { Haptics } from "@nativescript/haptics"; |
| 43 | +Checks if Haptics is supported on iOS. |
25 | 44 |
|
26 |
| -Haptics.selection(); |
27 |
| -``` |
| 45 | +--- |
| 46 | +### selection() |
28 | 47 |
|
29 |
| -##### JavaScript |
30 |
| -```js |
31 |
| -const Haptics = require("@nativescript/haptics").Haptics; |
| 48 | +```ts |
| 49 | +import { Haptics } from "@nativescript/haptics"; |
32 | 50 |
|
33 | 51 | Haptics.selection();
|
34 | 52 | ```
|
35 | 53 |
|
36 |
| -### `notification` |
37 |
| -Use notification feedback generators to indicate successes, failures, and warnings. |
| 54 | +### notification() |
38 | 55 |
|
39 |
| -There are 3 notification types: `HapticNotificationType.SUCCESS` (default), `.WARNING`, and `.ERROR`. |
40 |
| - |
41 |
| -##### TypeScript |
42 |
| -```js |
| 56 | +```ts |
43 | 57 | import { Haptics, HapticNotificationType } from "@nativescript/haptics";
|
44 | 58 |
|
45 | 59 | Haptics.notification(HapticNotificationType.ERROR);
|
46 | 60 | ```
|
47 | 61 |
|
48 |
| -### `impact` |
49 |
| -Use impact feedback generators to indicate that an impact has occurred. |
50 |
| -For example, you might trigger impact feedback when a user interface object |
51 |
| -collides with something or snaps into place. |
| 62 | +Use notification feedback generators to indicate success, failure, and warning. |
52 | 63 |
|
53 |
| -There are 3 impact styles: `HapticImpactType.LIGHT`, `.MEDIUM` (default), and `.HEAVY`. |
| 64 | +Other haptic notification types are: |
| 65 | +- `SUCCESS`(default) |
| 66 | +- `WARNING` |
| 67 | + |
| 68 | +### impact() |
54 | 69 |
|
55 |
| -##### TypeScript |
56 | 70 | ```js
|
57 | 71 | import { Haptics, HapticImpactType } from "@nativescript/haptics";
|
58 | 72 |
|
59 | 73 | Haptics.impact(HapticImpactType.HEAVY);
|
60 | 74 | ```
|
61 | 75 |
|
| 76 | +Use impact feedback generators to indicate that an impact has occurred. |
| 77 | +For example, you might trigger impact feedback when a user interface object |
| 78 | +collides with something or snaps into place. |
| 79 | + |
| 80 | +There are 3 impact types: |
| 81 | +- `LIGHT` |
| 82 | +- `MEDIUM` (default) |
| 83 | +- `HEAVY`. |
62 | 84 |
|
63 |
| -## HapticsFallback (requires at least iPhone 6s) |
| 85 | +### HapticsFallback |
64 | 86 |
|
65 |
| -With older phones you can use the following conditional to use the fallbacks: |
| 87 | +To use the haptics fallbacks, first check if there is support: |
66 | 88 |
|
67 |
| -``` |
| 89 | +```ts |
68 | 90 | if (!Haptics.isSupported() && Haptics.is6SAnd6SPlusSupported()) {
|
69 | 91 | // use HapticsFallback
|
70 | 92 | }
|
71 | 93 | ```
|
72 | 94 |
|
73 |
| -__BEWARE__ This uses an undocumented feature which may get your app rejected when reviewed by Apple. |
| 95 | +__BEWARE__ This uses an undocumented feature that may get your app rejected when reviewed by Apple. |
74 | 96 | [People have used this approach __without problems__ though.](http://stackoverflow.com/questions/32526868/taptic-in-ios-9)
|
75 | 97 |
|
76 |
| -### `weakBoom` |
| 98 | +### weakBoom() |
77 | 99 | This triggers the same effect as the 'Peek' in 'Peek & Pop', a very brief vibration.
|
78 | 100 |
|
79 |
| -##### TypeScript |
80 |
| -```js |
| 101 | +```ts |
81 | 102 | import { HapticsFallback } from "@nativescript/haptics";
|
82 | 103 |
|
83 | 104 | HapticsFallback.weakBoom();
|
84 | 105 | ```
|
85 | 106 |
|
86 |
| -##### JavaScript |
87 |
| -```js |
88 |
| -const HapticsFallback = require("@nativescript/haptics").HapticsFallback; |
| 107 | +### strongBoom() |
| 108 | +```ts |
| 109 | +import { HapticsFallback } from "@nativescript/haptics"; |
89 | 110 |
|
90 |
| -HapticsFallback.weakBoom(); |
| 111 | +HapticsFallback.strongBoom(); |
91 | 112 | ```
|
92 |
| - |
93 |
| -### `strongBoom` |
94 | 113 | This triggers the 'Pop' effect of 'Peek & Pop', which is a bit more profound than the 'Peek' effect.
|
95 | 114 |
|
96 |
| -Codewise this is exactly the same as `weakBoom`, except for the function name of course. |
97 |
| - |
98 |
| - |
99 |
| -### `burst` |
100 |
| -This triggers the 'Nope' effect you get when fi. force touching a home icon which doesn't have any action. It's a short burst of 3-ish 'weak booms'. |
| 115 | +### burst() |
| 116 | +```ts |
| 117 | +import { HapticsFallback } from "@nativescript/haptics"; |
101 | 118 |
|
102 |
| -Codewise this is exactly the same as `weakBoom` and `strongBoom`, except for the function name of course. |
| 119 | +HapticsFallback.burst(); |
| 120 | +``` |
| 121 | +This triggers the 'Nope' effect you get when force-touching a home icon that doesn't have any action. It's a short burst of 3-ish 'weak booms'. |
103 | 122 |
|
104 | 123 | ## Changelog
|
105 | 124 | * 3.0.0 Moved to @nativescript/haptics and added Android support. Adjusted naming conventions.
|
|
0 commit comments