1*f67462bcSTomasz Sapeta// Copyright 2015-present 650 Industries. All rights reserved. 2*f67462bcSTomasz Sapeta 3*f67462bcSTomasz Sapeta#import <React/RCTUtils.h> 4*f67462bcSTomasz Sapeta 5*f67462bcSTomasz Sapeta#import "EXDevMenuMotionInterceptor.h" 6*f67462bcSTomasz Sapeta#import "EXDevMenuManager.h" 7*f67462bcSTomasz Sapeta 8*f67462bcSTomasz Sapeta@import UIKit; 9*f67462bcSTomasz Sapeta 10*f67462bcSTomasz Sapetastatic BOOL isInstalled = NO; 11*f67462bcSTomasz Sapeta 12*f67462bcSTomasz Sapeta@implementation UIWindow (EXDevMenuMotionInterceptor) 13*f67462bcSTomasz Sapeta 14*f67462bcSTomasz Sapeta- (void)EX_motionEnded:(__unused UIEventSubtype)motion withEvent:(UIEvent *)event 15*f67462bcSTomasz Sapeta{ 16*f67462bcSTomasz Sapeta if (event.subtype == UIEventSubtypeMotionShake) { 17*f67462bcSTomasz Sapeta [[EXDevMenuManager sharedInstance] toggle]; 18*f67462bcSTomasz Sapeta } 19*f67462bcSTomasz Sapeta} 20*f67462bcSTomasz Sapeta 21*f67462bcSTomasz Sapeta@end 22*f67462bcSTomasz Sapeta 23*f67462bcSTomasz Sapeta@implementation EXDevMenuMotionInterceptor 24*f67462bcSTomasz Sapeta 25*f67462bcSTomasz Sapeta+ (void)install 26*f67462bcSTomasz Sapeta{ 27*f67462bcSTomasz Sapeta if (!isInstalled) { 28*f67462bcSTomasz Sapeta // Capture shake gesture from any window by swapping default implementation from UIWindow. 29*f67462bcSTomasz Sapeta RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(EX_motionEnded:withEvent:)); 30*f67462bcSTomasz Sapeta isInstalled = YES; 31*f67462bcSTomasz Sapeta } 32*f67462bcSTomasz Sapeta} 33*f67462bcSTomasz Sapeta 34*f67462bcSTomasz Sapeta+ (void)uninstall 35*f67462bcSTomasz Sapeta{ 36*f67462bcSTomasz Sapeta if (isInstalled) { 37*f67462bcSTomasz Sapeta // Bring back the original method. 38*f67462bcSTomasz Sapeta RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(EX_motionEnded:withEvent:)); 39*f67462bcSTomasz Sapeta isInstalled = NO; 40*f67462bcSTomasz Sapeta } 41*f67462bcSTomasz Sapeta} 42*f67462bcSTomasz Sapeta 43*f67462bcSTomasz Sapeta+ (BOOL)isInstalled 44*f67462bcSTomasz Sapeta{ 45*f67462bcSTomasz Sapeta return isInstalled; 46*f67462bcSTomasz Sapeta} 47*f67462bcSTomasz Sapeta 48*f67462bcSTomasz Sapeta@end 49