Skip to content

Commit a05a218

Browse files
author
Michael Kuczera
committed
ios adjustments
1 parent 7463a1e commit a05a218

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

ios/RNHapticFeedback.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
/* Begin PBXFileReference section */
2727
134814201AA4EA6300B7C361 /* libRNHapticFeedback.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNHapticFeedback.a; sourceTree = BUILT_PRODUCTS_DIR; };
28+
3FAF13E52C6144D7002E28B1 /* RNHapticFeedbackSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNHapticFeedbackSpec.h; path = RNHapticFeedback/RNHapticFeedbackSpec.h; sourceTree = "<group>"; };
2829
558CBA9028EF1100007CF242 /* RNHapticFeedback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNHapticFeedback.h; path = RNHapticFeedback/RNHapticFeedback.h; sourceTree = "<group>"; };
2930
558CBA9128EF1100007CF242 /* DeviceUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DeviceUtils.h; path = RNHapticFeedback/DeviceUtils.h; sourceTree = "<group>"; };
3031
558CBA9228EF1100007CF242 /* DeviceUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DeviceUtils.mm; path = RNHapticFeedback/DeviceUtils.mm; sourceTree = "<group>"; };
@@ -53,6 +54,7 @@
5354
58B511D21A9E6C8500147676 = {
5455
isa = PBXGroup;
5556
children = (
57+
3FAF13E52C6144D7002E28B1 /* RNHapticFeedbackSpec.h */,
5658
558CBA9128EF1100007CF242 /* DeviceUtils.h */,
5759
558CBA9228EF1100007CF242 /* DeviceUtils.mm */,
5860
558CBA9028EF1100007CF242 /* RNHapticFeedback.h */,
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
// Thanks to this guard, we won't import this header when we build for the old architecture.
21
#ifdef RCT_NEW_ARCH_ENABLED
32
#import "RNHapticFeedbackSpec.h"
3+
4+
@interface RNHapticFeedback : NSObject <NativeHapticFeedbackSpec>
45
#else
56
#import <React/RCTBridgeModule.h>
7+
8+
@interface RNHapticFeedback : NSObject <RCTBridgeModule>
69
#endif
710

811
#import <Foundation/Foundation.h>
912
#import <UIKit/UIKit.h>
1013

11-
#ifdef RCT_NEW_ARCH_ENABLED
12-
@interface RNHapticFeedback : NSObject <NativeHapticFeedbackSpec>
13-
#else
14-
@interface RNHapticFeedback : NSObject <RCTBridgeModule>
15-
#endif
16-
17-
typedef enum {
14+
typedef NS_ENUM(NSInteger, FeedbackType) {
1815
selection,
1916
impactLight,
2017
impactMedium,
@@ -24,9 +21,9 @@ typedef enum {
2421
notificationSuccess,
2522
notificationWarning,
2623
notificationError
27-
}FeedbackType;
24+
};
2825

2926
- (Boolean)supportsHaptic;
27+
- (void)triggerHapticFeedback:(NSString *)feedbackType;
3028

31-
@end
32-
29+
@end

ios/RNHapticFeedback/RNHapticFeedback.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ @implementation RNHapticFeedback
1414

1515
- (void)setBridge:(RCTBridge *)bridge
1616
{
17-
_bridge = bridge;
17+
@synthesize _bridge = bridge;
1818
}
1919

2020
- (dispatch_queue_t)methodQueue
@@ -31,7 +31,7 @@ - (dispatch_queue_t)methodQueue
3131
#else
3232
RCT_EXPORT_METHOD(trigger:(NSString *)type options:(NSDictionary *)options)
3333
{
34-
BOOL enableVibrateFallback = [[options objectForKey:@"enableVibrateFallback"]boolValue];
34+
BOOL enableVibrateFallback = [[options objectForKey:@"enableVibrateFallback"] boolValue];
3535
#endif
3636

3737
if ([self supportsHaptic]){
@@ -118,11 +118,11 @@ -(void)generateNotificationFeedback:(UINotificationFeedbackType)notificationType
118118

119119
// Thanks to this guard, we won't compile this code when we build for the old architecture.
120120
#ifdef RCT_NEW_ARCH_ENABLED
121-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
122-
(const facebook::react::ObjCTurboModule::InitParams &)params
123-
{
121+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params {
124122
return std::make_shared<facebook::react::NativeHapticFeedbackSpecJSI>(params);
125123
}
126124
#endif
127125

128126
@end
127+
@end
128+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// RNHapticFeedbackSpec.h
3+
// RNHapticFeedback
4+
//
5+
// Created by Michael Kuczera on 05.08.24.
6+
// Copyright © 2024 Facebook. All rights reserved.
7+
//
8+
#import <Foundation/Foundation.h>
9+
10+
@protocol NativeHapticFeedbackSpec <NSObject>
11+
12+
// Indicates whether the device supports haptic feedback
13+
- (Boolean)supportsHaptic;
14+
15+
// Triggers haptic feedback with the given intensity
16+
- (void)triggerHapticFeedback:(NSString *)feedbackType;
17+
18+
@end

0 commit comments

Comments
 (0)