@capacitor/haptics 1.0.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,55 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.1.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/haptics@1.1.2...@capacitor/haptics@1.1.3) (2021-11-03)
7
+
8
+ **Note:** Version bump only for package @capacitor/haptics
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.1.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/haptics@1.1.1...@capacitor/haptics@1.1.2) (2021-10-14)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * remove postpublish scripts ([#656](https://github.com/ionic-team/capacitor-plugins/issues/656)) ([ed6ac49](https://github.com/ionic-team/capacitor-plugins/commit/ed6ac499ebf4a47525071ccbfc36c27503e11f60))
20
+
21
+
22
+
23
+
24
+
25
+ ## [1.1.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/haptics@1.1.0...@capacitor/haptics@1.1.1) (2021-10-13)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * correct addListeners links ([#655](https://github.com/ionic-team/capacitor-plugins/issues/655)) ([f9871e7](https://github.com/ionic-team/capacitor-plugins/commit/f9871e7bd53478addb21155e148829f550c0e457))
31
+
32
+
33
+
34
+
35
+
36
+ # [1.1.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/haptics@1.0.3...@capacitor/haptics@1.1.0) (2021-09-27)
37
+
38
+
39
+ ### Features
40
+
41
+ * **haptics:** Implement duration for vibration ([#618](https://github.com/ionic-team/capacitor-plugins/issues/618)) ([78e6b68](https://github.com/ionic-team/capacitor-plugins/commit/78e6b6886fa50318b1bfbe229e7318e521e3c245))
42
+
43
+
44
+
45
+
46
+
47
+ ## [1.0.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/haptics@1.0.2...@capacitor/haptics@1.0.3) (2021-09-01)
48
+
49
+ **Note:** Version bump only for package @capacitor/haptics
50
+
51
+
52
+
53
+
54
+
6
55
  ## [1.0.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/haptics@1.0.1...@capacitor/haptics@1.0.2) (2021-06-23)
7
56
 
8
57
  **Note:** Version bump only for package @capacitor/haptics
@@ -7,10 +7,10 @@ Pod::Spec.new do |s|
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.license = package['license']
10
- s.homepage = package['repository']['url']
10
+ s.homepage = 'https://capacitorjs.com'
11
11
  s.author = package['author']
12
- s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
- s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
12
+ s.source = { :git => 'https://github.com/ionic-team/capacitor-plugins.git', :tag => package['name'] + '@' + package['version'] }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}', 'haptics/ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '12.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  The Haptics API provides physical feedback to the user through touch or vibration.
4
4
 
5
+ On devices that don't have Taptic Engine or Vibrator, the API calls will resolve without performing any action.
6
+
5
7
  ## Install
6
8
 
7
9
  ```bash
@@ -169,9 +171,9 @@ For example, call this when a user has lifted their finger from a control
169
171
 
170
172
  #### VibrateOptions
171
173
 
172
- | Prop | Type | Description | Default | Since |
173
- | -------------- | ------------------- | ---------------------------------------------------------------- | ---------------- | ----- |
174
- | **`duration`** | <code>number</code> | Duration of the vibration in milliseconds. Not supported in iOS. | <code>300</code> | 1.0.0 |
174
+ | Prop | Type | Description | Default | Since |
175
+ | -------------- | ------------------- | ----------------------------------------------------------------------------- | ---------------- | ----- |
176
+ | **`duration`** | <code>number</code> | Duration of the vibration in milliseconds. Not supported in iOS 12 and older. | <code>300</code> | 1.0.0 |
175
177
 
176
178
 
177
179
  ### Enums
package/dist/docs.json CHANGED
@@ -196,7 +196,7 @@
196
196
  "name": "since"
197
197
  }
198
198
  ],
199
- "docs": "Duration of the vibration in milliseconds.\n\nNot supported in iOS.",
199
+ "docs": "Duration of the vibration in milliseconds.\n\nNot supported in iOS 12 and older.",
200
200
  "complexTypes": [],
201
201
  "type": "number"
202
202
  }
@@ -105,7 +105,7 @@ export interface VibrateOptions {
105
105
  /**
106
106
  * Duration of the vibration in milliseconds.
107
107
  *
108
- * Not supported in iOS.
108
+ * Not supported in iOS 12 and older.
109
109
  *
110
110
  * @default 300
111
111
  * @since 1.0.0
package/dist/plugin.js CHANGED
@@ -127,5 +127,5 @@ var capacitorHaptics = (function (exports, core) {
127
127
 
128
128
  return exports;
129
129
 
130
- }({}, capacitorExports));
130
+ })({}, capacitorExports);
131
131
  //# sourceMappingURL=plugin.js.map
@@ -1,5 +1,6 @@
1
1
  import AudioToolbox
2
2
  import UIKit
3
+ import CoreHaptics
3
4
 
4
5
  @objc public class Haptics: NSObject {
5
6
 
@@ -34,4 +35,39 @@ import UIKit
34
35
  @objc public func vibrate() {
35
36
  AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)
36
37
  }
38
+
39
+ @objc public func vibrate(_ duration: Double) {
40
+ if #available(iOS 13, *) {
41
+ if CHHapticEngine.capabilitiesForHardware().supportsHaptics {
42
+ do {
43
+ let engine = try CHHapticEngine()
44
+ try engine.start()
45
+ engine.resetHandler = { [] in
46
+ do {
47
+ try engine.start()
48
+ } catch {
49
+ self.vibrate()
50
+ }
51
+ }
52
+ let intensity = CHHapticEventParameter(parameterID: .hapticIntensity, value: 1.0)
53
+ let sharpness = CHHapticEventParameter(parameterID: .hapticSharpness, value: 1.0)
54
+
55
+ let continuousEvent = CHHapticEvent(eventType: .hapticContinuous,
56
+ parameters: [intensity, sharpness],
57
+ relativeTime: 0.0,
58
+ duration: duration)
59
+ let pattern = try CHHapticPattern(events: [continuousEvent], parameters: [])
60
+ let player = try engine.makePlayer(with: pattern)
61
+
62
+ try player.start(atTime: 0)
63
+ } catch {
64
+ vibrate()
65
+ }
66
+ } else {
67
+ vibrate()
68
+ }
69
+ } else {
70
+ vibrate()
71
+ }
72
+ }
37
73
  }
@@ -56,8 +56,9 @@ public class HapticsPlugin: CAPPlugin {
56
56
  }
57
57
 
58
58
  @objc public func vibrate(_ call: CAPPluginCall) {
59
+ let duration = call.getDouble("duration", 300)/1000
59
60
  DispatchQueue.main.async {
60
- self.implementation.vibrate()
61
+ self.implementation.vibrate(duration)
61
62
  }
62
63
  call.resolve()
63
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/haptics",
3
- "version": "1.0.2",
3
+ "version": "1.1.3",
4
4
  "description": "The Haptics API provides physical feedback to the user through touch or vibration.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -33,7 +33,7 @@
33
33
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
34
  "verify:web": "npm run build",
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format",
36
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37
37
  "eslint": "eslint . --ext ts",
38
38
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
39
39
  "swiftlint": "node-swiftlint",
@@ -41,12 +41,13 @@
41
41
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
42
42
  "clean": "rimraf ./dist",
43
43
  "watch": "tsc --watch",
44
- "prepublishOnly": "npm run build"
44
+ "prepublishOnly": "npm run build",
45
+ "publish:cocoapod": "pod trunk push ./CapacitorHaptics.podspec --allow-warnings"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@capacitor/android": "^3.0.0",
48
49
  "@capacitor/core": "^3.0.0",
49
- "@capacitor/docgen": "0.0.17",
50
+ "@capacitor/docgen": "0.0.18",
50
51
  "@capacitor/ios": "^3.0.0",
51
52
  "@ionic/eslint-config": "^0.3.0",
52
53
  "@ionic/prettier-config": "~1.0.1",
@@ -78,5 +79,5 @@
78
79
  "publishConfig": {
79
80
  "access": "public"
80
81
  },
81
- "gitHead": "8b20a24ada3d3f96944aaa7023c4409c2bdb12c5"
82
+ "gitHead": "64df93225736e9dfad336562f5e53e5a2243052b"
82
83
  }