Ver código fonte

Fix keyboard shortcuts firing when typing into an alert view

Ryan Olson 10 anos atrás
pai
commit
b606d04944

+ 3 - 25
Classes/ExplorerToolbar/FLEXExplorerViewController.m

@@ -379,7 +379,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 - (NSArray *)allViewsInHierarchy
 {
     NSMutableArray *allViews = [NSMutableArray array];
-    NSArray *windows = [self allWindows];
+    NSArray *windows = [FLEXUtility allWindows];
     for (UIWindow *window in windows) {
         if (window != self.view.window) {
             [allViews addObject:window];
@@ -389,28 +389,6 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     return allViews;
 }
 
-- (NSArray *)allWindows
-{
-    BOOL includeInternalWindows = YES;
-    BOOL onlyVisibleWindows = NO;
-
-    NSArray *allWindowsComponents = @[@"al", @"lWindo", @"wsIncl", @"udingInt", @"ernalWin", @"dows:o", @"nlyVisi", @"bleWin", @"dows:"];
-    SEL allWindowsSelector = NSSelectorFromString([allWindowsComponents componentsJoinedByString:@""]);
-
-    NSMethodSignature *methodSignature = [[UIWindow class] methodSignatureForSelector:allWindowsSelector];
-    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
-
-    invocation.target = [UIWindow class];
-    invocation.selector = allWindowsSelector;
-    [invocation setArgument:&includeInternalWindows atIndex:2];
-    [invocation setArgument:&onlyVisibleWindows atIndex:3];
-    [invocation invoke];
-
-    __unsafe_unretained NSArray *windows = nil;
-    [invocation getReturnValue:&windows];
-    return windows;
-}
-
 - (UIWindow *)statusWindow
 {
     NSString *statusBarString = [NSString stringWithFormat:@"%@arWindow", @"_statusB"];
@@ -587,7 +565,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 - (NSArray *)viewsAtPoint:(CGPoint)tapPointInWindow skipHiddenViews:(BOOL)skipHidden
 {
     NSMutableArray *views = [NSMutableArray array];
-    for (UIWindow *window in [self allWindows]) {
+    for (UIWindow *window in [FLEXUtility allWindows]) {
         // Don't include the explorer's own window or subviews.
         if (window != self.view.window && [window pointInside:tapPointInWindow withEvent:nil]) {
             [views addObject:window];
@@ -602,7 +580,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     // Select in the window that would handle the touch, but don't just use the result of hitTest:withEvent: so we can still select views with interaction disabled.
     // Default to the the application's key window if none of the windows want the touch.
     UIWindow *windowForSelection = [[UIApplication sharedApplication] keyWindow];
-    for (UIWindow *window in [[self allWindows] reverseObjectEnumerator]) {
+    for (UIWindow *window in [[FLEXUtility allWindows] reverseObjectEnumerator]) {
         // Ignore the explorer's own window.
         if (window != self.view.window) {
             if ([window hitTest:tapPointInWindow withEvent:nil]) {

+ 1 - 1
Classes/Utility/FLEXKeyboardShortcutManager.m

@@ -244,7 +244,7 @@ static const long kFLEXCommandKeyCode = 0xe3;
     
     if (isKeyDown && [modifiedInput length] > 0 && interactionEnabled) {
         UIResponder *firstResponder = nil;
-        for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
+        for (UIWindow *window in [FLEXUtility allWindows]) {
             firstResponder = [window valueForKey:@"firstResponder"];
             if (firstResponder) {
                 break;

+ 2 - 0
Classes/Utility/FLEXUtility.h

@@ -39,6 +39,8 @@
 + (BOOL)isValidJSONData:(NSData *)data;
 + (NSData *)inflatedDataFromCompressedData:(NSData *)compressedData;
 
++ (NSArray *)allWindows;
+
 // Swizzling utilities
 
 + (SEL)swizzledSelectorForSelector:(SEL)selector;

+ 22 - 0
Classes/Utility/FLEXUtility.m

@@ -326,6 +326,28 @@
     return inflatedData;
 }
 
++ (NSArray *)allWindows
+{
+    BOOL includeInternalWindows = YES;
+    BOOL onlyVisibleWindows = NO;
+
+    NSArray *allWindowsComponents = @[@"al", @"lWindo", @"wsIncl", @"udingInt", @"ernalWin", @"dows:o", @"nlyVisi", @"bleWin", @"dows:"];
+    SEL allWindowsSelector = NSSelectorFromString([allWindowsComponents componentsJoinedByString:@""]);
+
+    NSMethodSignature *methodSignature = [[UIWindow class] methodSignatureForSelector:allWindowsSelector];
+    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
+
+    invocation.target = [UIWindow class];
+    invocation.selector = allWindowsSelector;
+    [invocation setArgument:&includeInternalWindows atIndex:2];
+    [invocation setArgument:&onlyVisibleWindows atIndex:3];
+    [invocation invoke];
+
+    __unsafe_unretained NSArray *windows = nil;
+    [invocation getReturnValue:&windows];
+    return windows;
+}
+
 + (SEL)swizzledSelectorForSelector:(SEL)selector
 {
     return NSSelectorFromString([NSString stringWithFormat:@"_flex_swizzle_%x_%@", arc4random(), NSStringFromSelector(selector)]);