nitro-ui-haptics 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/Package.swift +126 -0
- package/README.md +66 -2
- package/android/src/main/java/com/margelo/nitro/nitrouilibs/haptics/HybridHaptics.kt +52 -0
- package/ios/HybridHaptics.swift +40 -0
- package/nitro.json +23 -0
- package/package.json +62 -4
- package/src/Haptics.nitro.ts +29 -0
- package/src/index.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DewXIT Marcin Falkowski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// swift-tools-version: 6.4
|
|
2
|
+
|
|
3
|
+
import Foundation
|
|
4
|
+
import PackageDescription
|
|
5
|
+
|
|
6
|
+
let name = "NitroHaptics"
|
|
7
|
+
let generated = "nitrogen/generated"
|
|
8
|
+
let nitroDependencies: [Target.Dependency] = [
|
|
9
|
+
.product(name: "NitroModules", package: "nitro-core")
|
|
10
|
+
]
|
|
11
|
+
let cxxSettings: [CXXSetting] = [
|
|
12
|
+
.define("DEBUG", .when(configuration: .debug)),
|
|
13
|
+
.define("NDEBUG", .when(configuration: .release)),
|
|
14
|
+
.disableWarning("nullability-extension"),
|
|
15
|
+
]
|
|
16
|
+
let swiftSources = ["ios", "\(generated)/apple/swift"]
|
|
17
|
+
let bridgeSources = ["c++", "NitroHaptics-Swift-Cxx-Bridge.cpp", "NitroHapticsAutolinking.cpp"]
|
|
18
|
+
// Handwritten C++ in cpp/ is shared with Android and compiles with the generated shared C++.
|
|
19
|
+
let userCxxSources = ["cpp"].filter(exists)
|
|
20
|
+
let cxxSources = ["\(generated)/shared/c++"] + userCxxSources
|
|
21
|
+
func userHeaderSearchPaths(relativeTo targetPath: String) -> [CXXSetting] {
|
|
22
|
+
let packageDirectory = URL(fileURLWithPath: Context.packageDirectory)
|
|
23
|
+
let targetComponents = packageDirectory.appendingPathComponent(targetPath).standardizedFileURL.pathComponents
|
|
24
|
+
return userCxxSources.map { source in
|
|
25
|
+
let sourceURL = packageDirectory.appendingPathComponent(source)
|
|
26
|
+
var isDirectory: ObjCBool = false
|
|
27
|
+
FileManager.default.fileExists(atPath: sourceURL.path, isDirectory: &isDirectory)
|
|
28
|
+
let directory = isDirectory.boolValue ? sourceURL : sourceURL.deletingLastPathComponent()
|
|
29
|
+
let headerComponents = directory.standardizedFileURL.pathComponents
|
|
30
|
+
let commonCount = zip(targetComponents, headerComponents).prefix { $0.0 == $0.1 }.count
|
|
31
|
+
let relativeComponents =
|
|
32
|
+
Array(repeating: "..", count: targetComponents.count - commonCount)
|
|
33
|
+
+ headerComponents.dropFirst(commonCount)
|
|
34
|
+
return .headerSearchPath(relativeComponents.isEmpty ? "." : relativeComponents.joined(separator: "/"))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Bare-host integration. Nitrogen generates the bindings; this manifest owns the targets.
|
|
39
|
+
let package = Package(
|
|
40
|
+
name: name,
|
|
41
|
+
platforms: [.iOS(.v16), .macOS(.v13)],
|
|
42
|
+
products: [
|
|
43
|
+
.library(name: name, targets: ["\(name)Cxx", name, "\(name)SwiftBridge"])
|
|
44
|
+
],
|
|
45
|
+
dependencies: [
|
|
46
|
+
.package(path: "../nitro-core")
|
|
47
|
+
],
|
|
48
|
+
targets: [
|
|
49
|
+
.target(
|
|
50
|
+
name: "\(name)Cxx",
|
|
51
|
+
dependencies: nitroDependencies,
|
|
52
|
+
path: ".",
|
|
53
|
+
exclude: excludes(in: ".", keeping: cxxSources),
|
|
54
|
+
sources: cxxSources,
|
|
55
|
+
publicHeadersPath: "\(generated)/shared/c++/include",
|
|
56
|
+
cxxSettings: cxxSettings + userHeaderSearchPaths(relativeTo: ".")
|
|
57
|
+
),
|
|
58
|
+
.target(
|
|
59
|
+
name: "\(name)AppleCxx",
|
|
60
|
+
dependencies: [.target(name: "\(name)Cxx")] + nitroDependencies,
|
|
61
|
+
path: "\(generated)/apple/\(name)AppleCxx",
|
|
62
|
+
cxxSettings: cxxSettings
|
|
63
|
+
),
|
|
64
|
+
.target(
|
|
65
|
+
name: name,
|
|
66
|
+
dependencies: [.target(name: "\(name)AppleCxx")] + nitroDependencies,
|
|
67
|
+
path: ".",
|
|
68
|
+
exclude: excludes(in: ".", keeping: swiftSources),
|
|
69
|
+
sources: swiftSources,
|
|
70
|
+
cxxSettings: cxxSettings,
|
|
71
|
+
swiftSettings: [
|
|
72
|
+
// UIKit implementations run synchronously on the host's main thread.
|
|
73
|
+
.swiftLanguageMode(.v5),
|
|
74
|
+
.unsafeFlags(["-strict-concurrency=minimal"]),
|
|
75
|
+
.enableUpcomingFeature("InternalImportsByDefault"),
|
|
76
|
+
.enableUpcomingFeature("MemberImportVisibility"),
|
|
77
|
+
.interoperabilityMode(.Cxx),
|
|
78
|
+
.unsafeFlags(["-Xfrontend", "-clang-header-expose-decls=has-expose-attr-or-stdlib"]),
|
|
79
|
+
.unsafeFlags([
|
|
80
|
+
"-Xfrontend", "-clang-header-expose-module",
|
|
81
|
+
"-Xfrontend", "NitroModules=NitroModules-Swift.h",
|
|
82
|
+
]),
|
|
83
|
+
]
|
|
84
|
+
),
|
|
85
|
+
.target(
|
|
86
|
+
name: "\(name)SwiftBridge",
|
|
87
|
+
dependencies: [.target(name: name), .target(name: "\(name)AppleCxx")] + nitroDependencies,
|
|
88
|
+
path: "\(generated)/apple",
|
|
89
|
+
exclude: excludes(in: "\(generated)/apple", keeping: bridgeSources) + ["c++/include"],
|
|
90
|
+
sources: bridgeSources,
|
|
91
|
+
publicHeadersPath: "c++/include",
|
|
92
|
+
cxxSettings: cxxSettings + userHeaderSearchPaths(relativeTo: "\(generated)/apple") + [
|
|
93
|
+
.unsafeFlags(["-I${GENERATED_MODULEMAP_DIR}", "-fno-modules"])
|
|
94
|
+
]
|
|
95
|
+
),
|
|
96
|
+
],
|
|
97
|
+
cxxLanguageStandard: .cxx20
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
func exists(_ path: String) -> Bool {
|
|
101
|
+
FileManager.default.fileExists(
|
|
102
|
+
atPath: URL(fileURLWithPath: Context.packageDirectory).appendingPathComponent(path).path
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func excludes(in path: String, keeping sources: [String]) -> [String] {
|
|
107
|
+
var parents: Set<String> = [""]
|
|
108
|
+
for source in sources {
|
|
109
|
+
var components = source.split(separator: "/").dropLast()
|
|
110
|
+
while !components.isEmpty {
|
|
111
|
+
parents.insert(components.joined(separator: "/"))
|
|
112
|
+
components = components.dropLast()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let root = URL(fileURLWithPath: Context.packageDirectory).appendingPathComponent(path)
|
|
116
|
+
return parents.sorted().flatMap { parent in
|
|
117
|
+
let entries =
|
|
118
|
+
(try? FileManager.default.contentsOfDirectory(
|
|
119
|
+
atPath: root.appendingPathComponent(parent).path)) ?? []
|
|
120
|
+
return entries.sorted().compactMap { entry in
|
|
121
|
+
let entryPath = parent.isEmpty ? entry : "\(parent)/\(entry)"
|
|
122
|
+
return entry.hasPrefix(".") || sources.contains(entryPath) || parents.contains(entryPath)
|
|
123
|
+
? nil : entryPath
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# nitro-ui-haptics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/nitro-ui-haptics)
|
|
4
|
+
[](https://github.com/DewXIT/nitro-ui-haptics/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Haptic feedback for [NitroUI](https://github.com/margelo/nitro-ui) apps on iOS and Android.
|
|
8
|
+
|
|
9
|
+
<table>
|
|
10
|
+
<tr>
|
|
11
|
+
<th>iOS</th>
|
|
12
|
+
<th>Android</th>
|
|
13
|
+
</tr>
|
|
14
|
+
<tr>
|
|
15
|
+
<td><img src="https://raw.githubusercontent.com/DewXIT/nitro-ui-haptics/main/.github/assets/demo-ios.gif" width="280" alt="Haptics demo on iOS"></td>
|
|
16
|
+
<td><img src="https://raw.githubusercontent.com/DewXIT/nitro-ui-haptics/main/.github/assets/demo-android.gif" width="280" alt="Haptics demo on Android"></td>
|
|
17
|
+
</tr>
|
|
18
|
+
</table>
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
bun add nitro-ui-haptics
|
|
24
|
+
bun run nitro-ui prepare
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then rebuild the native app.
|
|
28
|
+
|
|
29
|
+
## Use
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Haptics } from 'nitro-ui-haptics'
|
|
33
|
+
|
|
34
|
+
Haptics.impact('medium') // 'light' | 'medium' | 'heavy' | 'soft' | 'rigid'
|
|
35
|
+
Haptics.notification('success') // 'success' | 'warning' | 'error'
|
|
36
|
+
Haptics.selection()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Platform behavior
|
|
40
|
+
|
|
41
|
+
| Call | iOS | Android |
|
|
42
|
+
| --- | --- | --- |
|
|
43
|
+
| `impact('light' / 'soft')` | `UIImpactFeedbackGenerator` | `KEYBOARD_TAP` |
|
|
44
|
+
| `impact('medium')` | `UIImpactFeedbackGenerator` | `VIRTUAL_KEY` |
|
|
45
|
+
| `impact('heavy' / 'rigid')` | `UIImpactFeedbackGenerator` | `LONG_PRESS` |
|
|
46
|
+
| `notification('success')` | `UINotificationFeedbackGenerator` | `CONFIRM` (API 30+), else `VIRTUAL_KEY` |
|
|
47
|
+
| `notification('warning')` | `UINotificationFeedbackGenerator` | `LONG_PRESS` |
|
|
48
|
+
| `notification('error')` | `UINotificationFeedbackGenerator` | `REJECT` (API 30+), else `LONG_PRESS` |
|
|
49
|
+
| `selection()` | `UISelectionFeedbackGenerator` | `CLOCK_TICK` |
|
|
50
|
+
|
|
51
|
+
On Android, feedback plays through the window's `performHapticFeedback`. It follows the user's touch-feedback setting and needs no `VIBRATE` permission. Test haptics on a physical device.
|
|
52
|
+
|
|
53
|
+
## Compatibility
|
|
54
|
+
|
|
55
|
+
- NitroUI SDK `0.2.x` with `nitro-core` `1.0.0-alpha` (Nitro v1, `bare` environment). `nitro-core` is a peer dependency, so the library follows the SDK version your app uses.
|
|
56
|
+
|
|
57
|
+
## Related
|
|
58
|
+
|
|
59
|
+
More NitroUI modules from DewXIT: [`nitro-ui-clipboard`](https://github.com/DewXIT/nitro-ui-clipboard) · [`nitro-ui-share`](https://github.com/DewXIT/nitro-ui-share).
|
|
60
|
+
|
|
61
|
+
## Contributing
|
|
62
|
+
|
|
63
|
+
Bug reports and pull requests are welcome. See [CONTRIBUTING.md](https://github.com/DewXIT/nitro-ui-haptics/blob/main/CONTRIBUTING.md). The [`example/`](https://github.com/DewXIT/nitro-ui-haptics/tree/main/example) app shows every API in a realistic screen.
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
[MIT](LICENSE) © DewXIT Marcin Falkowski
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package com.margelo.nitro.nitrouilibs.haptics
|
|
2
|
+
|
|
3
|
+
import android.os.Build
|
|
4
|
+
import android.view.HapticFeedbackConstants
|
|
5
|
+
import com.margelo.nitroui.runtime.NitroActivity
|
|
6
|
+
import com.margelo.nitroui.runtime.NitroActivityInitializer
|
|
7
|
+
import java.lang.ref.WeakReference
|
|
8
|
+
|
|
9
|
+
/** Keeps the current Activity so feedback plays through its window. */
|
|
10
|
+
object HapticsActivity : NitroActivityInitializer {
|
|
11
|
+
internal var current = WeakReference<NitroActivity>(null)
|
|
12
|
+
|
|
13
|
+
override fun onCreate(activity: NitroActivity) {
|
|
14
|
+
current = WeakReference(activity)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class HybridHaptics : HybridHapticsSpec() {
|
|
19
|
+
companion object : HybridHapticsSpec.Companion {
|
|
20
|
+
private fun perform(constant: Int) {
|
|
21
|
+
val view = HapticsActivity.current.get()?.window?.decorView ?: return
|
|
22
|
+
view.performHapticFeedback(constant)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun impact(style: ImpactStyle) {
|
|
26
|
+
perform(
|
|
27
|
+
when (style) {
|
|
28
|
+
ImpactStyle.LIGHT, ImpactStyle.SOFT -> HapticFeedbackConstants.KEYBOARD_TAP
|
|
29
|
+
ImpactStyle.MEDIUM -> HapticFeedbackConstants.VIRTUAL_KEY
|
|
30
|
+
ImpactStyle.HEAVY, ImpactStyle.RIGID -> HapticFeedbackConstants.LONG_PRESS
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun notification(type: NotificationType) {
|
|
36
|
+
val modern = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
|
|
37
|
+
perform(
|
|
38
|
+
when (type) {
|
|
39
|
+
NotificationType.SUCCESS ->
|
|
40
|
+
if (modern) HapticFeedbackConstants.CONFIRM else HapticFeedbackConstants.VIRTUAL_KEY
|
|
41
|
+
NotificationType.WARNING -> HapticFeedbackConstants.LONG_PRESS
|
|
42
|
+
NotificationType.ERROR ->
|
|
43
|
+
if (modern) HapticFeedbackConstants.REJECT else HapticFeedbackConstants.LONG_PRESS
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun selection() {
|
|
49
|
+
perform(HapticFeedbackConstants.CLOCK_TICK)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
internal import NitroModules
|
|
2
|
+
internal import UIKit
|
|
3
|
+
|
|
4
|
+
final class HybridHaptics: HybridHapticsSpec {
|
|
5
|
+
// Generators are reused so repeated feedback stays low-latency.
|
|
6
|
+
private static var impactGenerators: [UIImpactFeedbackGenerator.FeedbackStyle: UIImpactFeedbackGenerator] = [:]
|
|
7
|
+
private static let notificationGenerator = UINotificationFeedbackGenerator()
|
|
8
|
+
private static let selectionGenerator = UISelectionFeedbackGenerator()
|
|
9
|
+
|
|
10
|
+
static func impact(style: ImpactStyle) throws {
|
|
11
|
+
let feedbackStyle: UIImpactFeedbackGenerator.FeedbackStyle
|
|
12
|
+
switch style {
|
|
13
|
+
case .light: feedbackStyle = .light
|
|
14
|
+
case .medium: feedbackStyle = .medium
|
|
15
|
+
case .heavy: feedbackStyle = .heavy
|
|
16
|
+
case .soft: feedbackStyle = .soft
|
|
17
|
+
case .rigid: feedbackStyle = .rigid
|
|
18
|
+
}
|
|
19
|
+
let generator = impactGenerators[feedbackStyle] ?? UIImpactFeedbackGenerator(style: feedbackStyle)
|
|
20
|
+
impactGenerators[feedbackStyle] = generator
|
|
21
|
+
generator.impactOccurred()
|
|
22
|
+
generator.prepare()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static func notification(type: NotificationType) throws {
|
|
26
|
+
let feedbackType: UINotificationFeedbackGenerator.FeedbackType
|
|
27
|
+
switch type {
|
|
28
|
+
case .success: feedbackType = .success
|
|
29
|
+
case .warning: feedbackType = .warning
|
|
30
|
+
case .error: feedbackType = .error
|
|
31
|
+
}
|
|
32
|
+
notificationGenerator.notificationOccurred(feedbackType)
|
|
33
|
+
notificationGenerator.prepare()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static func selection() throws {
|
|
37
|
+
selectionGenerator.selectionChanged()
|
|
38
|
+
selectionGenerator.prepare()
|
|
39
|
+
}
|
|
40
|
+
}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"environment": "bare",
|
|
4
|
+
"cxxNamespace": [
|
|
5
|
+
"nitrouilibs",
|
|
6
|
+
"haptics"
|
|
7
|
+
],
|
|
8
|
+
"apple": {
|
|
9
|
+
"moduleName": "NitroHaptics"
|
|
10
|
+
},
|
|
11
|
+
"android": {
|
|
12
|
+
"namespace": [
|
|
13
|
+
"nitrouilibs",
|
|
14
|
+
"haptics"
|
|
15
|
+
],
|
|
16
|
+
"cxxLibName": "NitroHaptics"
|
|
17
|
+
},
|
|
18
|
+
"ignorePaths": [
|
|
19
|
+
"**/node_modules",
|
|
20
|
+
"**/.build",
|
|
21
|
+
"**/.swiftpm"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-ui-haptics",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Haptic feedback for NitroUI apps on iOS and Android: impact, notification and selection.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nitro-ui",
|
|
7
|
+
"nitroui",
|
|
8
|
+
"nitro",
|
|
9
|
+
"nitro-modules",
|
|
10
|
+
"haptics",
|
|
11
|
+
"vibration",
|
|
12
|
+
"feedback",
|
|
13
|
+
"ios",
|
|
14
|
+
"android"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/DewXIT/nitro-ui-haptics#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/DewXIT/nitro-ui-haptics/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/DewXIT/nitro-ui-haptics.git",
|
|
23
|
+
"directory": "package"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "DewXIT Marcin Falkowski",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"module": "src/index.ts",
|
|
29
|
+
"types": "src/index.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./src/index.ts",
|
|
33
|
+
"default": "./src/index.ts"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"imports": {
|
|
38
|
+
"#nitro/*": "./nitrogen/generated/shared/javascript/*.cjs"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"src",
|
|
42
|
+
"ios",
|
|
43
|
+
"android",
|
|
44
|
+
"nitro.json",
|
|
45
|
+
"Package.swift",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE"
|
|
48
|
+
],
|
|
49
|
+
"nitroUI": {
|
|
50
|
+
"android": {
|
|
51
|
+
"activityInitializer": "com.margelo.nitro.nitrouilibs.haptics.HapticsActivity"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"nitro-core": ">=1.0.0-alpha.0 <2.0.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"specs": "nitrogen . --out nitrogen/generated",
|
|
59
|
+
"typecheck": "tsc --noEmit"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Android, iOS, type HybridObject } from 'nitro-core'
|
|
2
|
+
|
|
3
|
+
export * from '#nitro/Haptics'
|
|
4
|
+
|
|
5
|
+
/** How strong a physical impact feels. `soft` and `rigid` map to the nearest Android feedback. */
|
|
6
|
+
export type ImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid'
|
|
7
|
+
|
|
8
|
+
/** The outcome a notification haptic communicates. */
|
|
9
|
+
export type NotificationType = 'success' | 'warning' | 'error'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Plays system haptic feedback.
|
|
13
|
+
*
|
|
14
|
+
* iOS uses UIKit feedback generators. Android uses the window's
|
|
15
|
+
* `performHapticFeedback`, which follows the user's touch-feedback setting
|
|
16
|
+
* and needs no `VIBRATE` permission.
|
|
17
|
+
*/
|
|
18
|
+
@iOS({ language: 'swift', implementation: { className: 'HybridHaptics' } })
|
|
19
|
+
@Android({ language: 'kotlin', implementation: { className: 'HybridHaptics' } })
|
|
20
|
+
export declare class Haptics extends HybridObject {
|
|
21
|
+
/** Plays an impact, such as a view snapping into place. */
|
|
22
|
+
static impact(style: ImpactStyle): void
|
|
23
|
+
|
|
24
|
+
/** Plays a notification pattern for a completed, risky or failed action. */
|
|
25
|
+
static notification(type: NotificationType): void
|
|
26
|
+
|
|
27
|
+
/** Plays a light tick for a changing selection, such as a picker value. */
|
|
28
|
+
static selection(): void
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Haptics, type ImpactStyle, type NotificationType } from './Haptics.nitro'
|