Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ Notification haptics provide feedback about the outcome of a task or action, suc

Selection haptics provide feedback while the values of a UI element are changing, see [HIG for visualization](https://developer.apple.com/design/human-interface-guidelines/playing-haptics#Selection).

### `Haptics.impactWithIntensity(style: 'light' | 'medium' | 'heavy' | 'soft' | 'rigid', intensity: number)`

**This function is not supported on Android**

The `impactWithIntensity` provides haptic feedback with a customizable intensity level. This allows to adjust the strength of the haptic feedback based on the needs of the application, offering a more refined and dynamic user experience.

`intensity`: A number between `0.0` and `1` that determines the strength of the haptic feedback, see [Triggers impact feedback with a specific intensity](https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator/impactoccurred(intensity:))

## License

MIT
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class HybridHaptics: HybridHapticsSpec() {
vibrate(selectionType)
}

@DoNotStrip
@Keep
override fun impactWithIntensity(style: ImpactFeedbackStyle, intensity: Double): Unit {
Log.e("Haptics", "impactWithIntensity is unsupported on Android")
}

override val memorySize: Long
get() = 0L

Expand Down
4 changes: 4 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function App(): React.JSX.Element {
onPress={() => Haptics.notification('warning')}
/>
<Button title="Selection" onPress={() => Haptics.selection()} />
<Button
title="Impact With Intensity"
onPress={() => Haptics.impactWithIntensity('light', 0.5)}
/>
</View>
</ScrollView>
</SafeAreaView>
Expand Down
12 changes: 12 additions & 0 deletions ios/HybridHaptics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class HybridHaptics : HybridHapticsSpec {
generator.prepare()
generator.selectionChanged()
}

// Custom method to allow impact with intensity
func impactWithIntensity(style: ImpactFeedbackStyle, intensity: Double) throws -> Void {
// Ensure intensity is within the range (0, 1]
guard intensity >= 0 && intensity <= 1 else {
throw NSError(domain: "HybridHaptics", code: 1, userInfo: [NSLocalizedDescriptionKey: "Intensity must be greater than 0 and less than or equal to 1"])
}
// Create feedback generator with the appropriate style
let generator = UIImpactFeedbackGenerator(style: style.toUIImpactFeedbackType())
generator.prepare()
generator.impactOccurred(intensity: CGFloat(intensity))
}
}

extension ImpactFeedbackStyle {
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/NitroHaptics+autolinking.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# NitroHaptics+autolinking.cmake
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
# https://github.com/mrousavy/nitro
# Copyright © 2024 Marc Rousavy @ Margelo
# Copyright © 2025 Marc Rousavy @ Margelo
#

# This is a CMake file that adds all files generated by Nitrogen
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/NitroHaptics+autolinking.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHaptics+autolinking.gradle
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

/// This is a Gradle file that adds all files generated by Nitrogen
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/NitroHapticsOnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHapticsOnLoad.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "NitroHapticsOnLoad.hpp"
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/NitroHapticsOnLoad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHapticsOnLoad.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include <jni.h>
Expand Down
6 changes: 5 additions & 1 deletion nitrogen/generated/android/c++/JHybridHapticsSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JHybridHapticsSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "JHybridHapticsSpec.hpp"
Expand Down Expand Up @@ -50,5 +50,9 @@ namespace margelo::nitro::haptics {
static const auto method = _javaPart->getClass()->getMethod<void()>("selection");
method(_javaPart);
}
void JHybridHapticsSpec::impactWithIntensity(ImpactFeedbackStyle style, double intensity) {
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JImpactFeedbackStyle> /* style */, double /* intensity */)>("impactWithIntensity");
method(_javaPart, JImpactFeedbackStyle::fromCpp(style), intensity);
}

} // namespace margelo::nitro::haptics
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JHybridHapticsSpec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpec.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down Expand Up @@ -54,6 +54,7 @@ namespace margelo::nitro::haptics {
void impact(ImpactFeedbackStyle style) override;
void notification(NotificationFeedbackType type) override;
void selection() override;
void impactWithIntensity(ImpactFeedbackStyle style, double intensity) override;

private:
friend HybridBase;
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/c++/JImpactFeedbackStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JImpactFeedbackStyle.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JNotificationFeedbackType.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpec.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

package com.margelo.nitro.haptics
Expand Down Expand Up @@ -52,6 +52,10 @@ abstract class HybridHapticsSpec: HybridObject() {
@DoNotStrip
@Keep
abstract fun selection(): Unit

@DoNotStrip
@Keep
abstract fun impactWithIntensity(style: ImpactFeedbackStyle, intensity: Double): Unit

private external fun initHybrid(): HybridData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// ImpactFeedbackStyle.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

package com.margelo.nitro.haptics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NotificationFeedbackType.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

package com.margelo.nitro.haptics
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/NitroHaptics+autolinking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# NitroHaptics+autolinking.rb
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
# https://github.com/mrousavy/nitro
# Copyright © 2024 Marc Rousavy @ Margelo
# Copyright © 2025 Marc Rousavy @ Margelo
#

# This is a Ruby script that adds all files generated by Nitrogen
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/NitroHaptics-Swift-Cxx-Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHaptics-Swift-Cxx-Bridge.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "NitroHaptics-Swift-Cxx-Bridge.hpp"
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/NitroHaptics-Swift-Cxx-Bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHaptics-Swift-Cxx-Bridge.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/NitroHaptics-Swift-Cxx-Umbrella.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHaptics-Swift-Cxx-Umbrella.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/NitroHapticsAutolinking.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHapticsAutolinking.mm
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#import <Foundation/Foundation.h>
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/NitroHapticsAutolinking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NitroHapticsAutolinking.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

public final class NitroHapticsAutolinking {
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/c++/HybridHapticsSpecSwift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpecSwift.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "HybridHapticsSpecSwift.hpp"
Expand Down
8 changes: 7 additions & 1 deletion nitrogen/generated/ios/c++/HybridHapticsSpecSwift.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpecSwift.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down Expand Up @@ -75,6 +75,12 @@ namespace margelo::nitro::haptics {
std::rethrow_exception(__result.error());
}
}
inline void impactWithIntensity(ImpactFeedbackStyle style, double intensity) override {
auto __result = _swiftPart.impactWithIntensity(static_cast<int>(style), std::forward<decltype(intensity)>(intensity));
if (__result.hasError()) [[unlikely]] {
std::rethrow_exception(__result.error());
}
}

private:
NitroHaptics::HybridHapticsSpec_cxx _swiftPart;
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/ios/swift/HybridHapticsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpec.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

import Foundation
Expand All @@ -17,6 +17,7 @@ public protocol HybridHapticsSpec_protocol: AnyObject {
func impact(style: ImpactFeedbackStyle) throws -> Void
func notification(type: NotificationFeedbackType) throws -> Void
func selection() throws -> Void
func impactWithIntensity(style: ImpactFeedbackStyle, intensity: Double) throws -> Void
}

/// See ``HybridHapticsSpec``
Expand Down
13 changes: 12 additions & 1 deletion nitrogen/generated/ios/swift/HybridHapticsSpec_cxx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpec_cxx.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

import Foundation
Expand Down Expand Up @@ -132,4 +132,15 @@ public class HybridHapticsSpec_cxx {
return bridge.create_Result_void_(__exceptionPtr)
}
}

@inline(__always)
public func impactWithIntensity(style: Int32, intensity: Double) -> bridge.Result_void_ {
do {
try self.__implementation.impactWithIntensity(style: margelo.nitro.haptics.ImpactFeedbackStyle(rawValue: style)!, intensity: intensity)
return bridge.create_Result_void_()
} catch (let __error) {
let __exceptionPtr = __error.toCpp()
return bridge.create_Result_void_(__exceptionPtr)
}
}
}
2 changes: 1 addition & 1 deletion nitrogen/generated/ios/swift/ImpactFeedbackStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// ImpactFeedbackStyle.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NotificationFeedbackType.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

/**
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/shared/c++/HybridHapticsSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "HybridHapticsSpec.hpp"
Expand All @@ -17,6 +17,7 @@ namespace margelo::nitro::haptics {
prototype.registerHybridMethod("impact", &HybridHapticsSpec::impact);
prototype.registerHybridMethod("notification", &HybridHapticsSpec::notification);
prototype.registerHybridMethod("selection", &HybridHapticsSpec::selection);
prototype.registerHybridMethod("impactWithIntensity", &HybridHapticsSpec::impactWithIntensity);
});
}

Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/shared/c++/HybridHapticsSpec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridHapticsSpec.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down Expand Up @@ -55,6 +55,7 @@ namespace margelo::nitro::haptics {
virtual void impact(ImpactFeedbackStyle style) = 0;
virtual void notification(NotificationFeedbackType type) = 0;
virtual void selection() = 0;
virtual void impactWithIntensity(ImpactFeedbackStyle style, double intensity) = 0;

protected:
// Hybrid Setup
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/shared/c++/ImpactFeedbackStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// ImpactFeedbackStyle.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/shared/c++/NotificationFeedbackType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// NotificationFeedbackType.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
1 change: 1 addition & 0 deletions src/specs/Haptics.nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface Haptics
impact(style: ImpactFeedbackStyle): void;
notification(type: NotificationFeedbackType): void;
selection(): void;
impactWithIntensity(style: ImpactFeedbackStyle, intensity: number): void;
}