Skip to content

Commit

Permalink
ios adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kuczera committed Aug 5, 2024
1 parent 7463a1e commit a05a218
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions ios/RNHapticFeedback.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libRNHapticFeedback.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNHapticFeedback.a; sourceTree = BUILT_PRODUCTS_DIR; };
3FAF13E52C6144D7002E28B1 /* RNHapticFeedbackSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNHapticFeedbackSpec.h; path = RNHapticFeedback/RNHapticFeedbackSpec.h; sourceTree = "<group>"; };
558CBA9028EF1100007CF242 /* RNHapticFeedback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNHapticFeedback.h; path = RNHapticFeedback/RNHapticFeedback.h; sourceTree = "<group>"; };
558CBA9128EF1100007CF242 /* DeviceUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DeviceUtils.h; path = RNHapticFeedback/DeviceUtils.h; sourceTree = "<group>"; };
558CBA9228EF1100007CF242 /* DeviceUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DeviceUtils.mm; path = RNHapticFeedback/DeviceUtils.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -53,6 +54,7 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
3FAF13E52C6144D7002E28B1 /* RNHapticFeedbackSpec.h */,
558CBA9128EF1100007CF242 /* DeviceUtils.h */,
558CBA9228EF1100007CF242 /* DeviceUtils.mm */,
558CBA9028EF1100007CF242 /* RNHapticFeedback.h */,
Expand Down
19 changes: 8 additions & 11 deletions ios/RNHapticFeedback/RNHapticFeedback.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// Thanks to this guard, we won't import this header when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
#import "RNHapticFeedbackSpec.h"

@interface RNHapticFeedback : NSObject <NativeHapticFeedbackSpec>
#else
#import <React/RCTBridgeModule.h>

@interface RNHapticFeedback : NSObject <RCTBridgeModule>
#endif

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#ifdef RCT_NEW_ARCH_ENABLED
@interface RNHapticFeedback : NSObject <NativeHapticFeedbackSpec>
#else
@interface RNHapticFeedback : NSObject <RCTBridgeModule>
#endif

typedef enum {
typedef NS_ENUM(NSInteger, FeedbackType) {
selection,
impactLight,
impactMedium,
Expand All @@ -24,9 +21,9 @@ typedef enum {
notificationSuccess,
notificationWarning,
notificationError
}FeedbackType;
};

- (Boolean)supportsHaptic;
- (void)triggerHapticFeedback:(NSString *)feedbackType;

@end

@end
10 changes: 5 additions & 5 deletions ios/RNHapticFeedback/RNHapticFeedback.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ @implementation RNHapticFeedback

- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
@synthesize _bridge = bridge;
}

- (dispatch_queue_t)methodQueue
Expand All @@ -31,7 +31,7 @@ - (dispatch_queue_t)methodQueue
#else
RCT_EXPORT_METHOD(trigger:(NSString *)type options:(NSDictionary *)options)
{
BOOL enableVibrateFallback = [[options objectForKey:@"enableVibrateFallback"]boolValue];
BOOL enableVibrateFallback = [[options objectForKey:@"enableVibrateFallback"] boolValue];
#endif

if ([self supportsHaptic]){
Expand Down Expand Up @@ -118,11 +118,11 @@ -(void)generateNotificationFeedback:(UINotificationFeedbackType)notificationType

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

@end
@end

18 changes: 18 additions & 0 deletions ios/RNHapticFeedback/RNHapticFeedbackSpec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// RNHapticFeedbackSpec.h
// RNHapticFeedback
//
// Created by Michael Kuczera on 05.08.24.
// Copyright © 2024 Facebook. All rights reserved.
//
#import <Foundation/Foundation.h>

@protocol NativeHapticFeedbackSpec <NSObject>

// Indicates whether the device supports haptic feedback
- (Boolean)supportsHaptic;

// Triggers haptic feedback with the given intensity
- (void)triggerHapticFeedback:(NSString *)feedbackType;

@end

0 comments on commit a05a218

Please sign in to comment.