Skip to content

Commit

Permalink
Fix iOS issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Doko-Demo-Doa committed May 15, 2021
1 parent 8426803 commit 3cfb50c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion ios/RNShakeEvent.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface RNShakeEvent : NSObject <RCTBridgeModule>
@interface RNShakeEvent : RCTEventEmitter <RCTBridgeModule>

@end
38 changes: 28 additions & 10 deletions ios/RNShakeEvent.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "RNShakeEvent.h"

#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>

static NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification";
static NSString *const RNShakeEventName = @"ShakeEvent";

#if !RCT_DEV

Expand All @@ -22,10 +22,16 @@ - (void)handleShakeEvent:(__unused UIEventSubtype)motion withEvent:(UIEvent *)ev

@implementation RNShakeEvent

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)supportedEvents
{
return
@[
RNShakeEventName
];
}

+ (void)initialize
{
RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(handleShakeEvent:withEvent:));
Expand All @@ -34,7 +40,7 @@ + (void)initialize
- (instancetype)init
{
if ((self = [super init])) {
RCTLogInfo(@"RNShakeEvent: started in debug mode");
RCTLogInfo(@"RNShakeEvent: Started in debug mode");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(motionEnded:)
name:RCTShowDevMenuNotification
Expand All @@ -50,8 +56,11 @@ - (void)dealloc

- (void)motionEnded:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"ShakeEvent"
body:nil];
[self sendEvent];
}

- (void)sendEvent {
[self sendEventWithName:RNShakeEventName body:nil];
}

@end
Expand All @@ -60,10 +69,16 @@ - (void)motionEnded:(NSNotification *)notification

@implementation RNShakeEvent

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)supportedEvents
{
return
@[
RNShakeEventName
];
}

- (instancetype)init
{
if ((self = [super init])) {
Expand All @@ -82,8 +97,11 @@ - (void)dealloc

- (void)motionEnded:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"ShakeEvent"
body:nil];
[self sendEvent];
}

- (void)sendEvent {
[self sendEventWithName:RNShakeEventName body:nil];
}

+ (BOOL)requiresMainQueueSetup {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-shake",
"version": "4.0.0",
"version": "4.0.2",
"description": "Detect shake event on Android and iOS",
"homepage": "https://github.com/Doko-Demo-Doa/react-native-shake",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion react-native-shake.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.homepage = package['homepage']
s.platform = :ios, "10.0"

s.source = { :git => package_json["repository"]["url"].gsub(/(http.*)/).first, :tag => "v#{s.version}" }
s.source = { :git => "https://github.com/Doko-Demo-Doa/react-native-shake", :tag => "v#{s.version}" }
s.source_files = "ios/**/*.{h,m,swift}"

s.dependency 'React'
Expand Down

0 comments on commit 3cfb50c

Please sign in to comment.