Просмотр исходного кода

Fix simulator up/down arrow scrolling shortcuts

Tanner Bennett лет назад: 6
Родитель
Сommit
e53e083507

+ 10 - 4
Classes/ExplorerInterface/FLEXExplorerViewController.h

@@ -8,6 +8,7 @@
 
 #import <UIKit/UIKit.h>
 
+@class FLEXWindow;
 @protocol FLEXExplorerViewControllerDelegate;
 
 /// A view controller that manages the FLEX toolbar.
@@ -30,10 +31,15 @@
 - (void)toggleMoveTool;
 - (void)toggleViewsTool;
 - (void)toggleMenuTool;
-- (void)handleDownArrowKeyPressed;
-- (void)handleUpArrowKeyPressed;
-- (void)handleRightArrowKeyPressed;
-- (void)handleLeftArrowKeyPressed;
+
+/// @return YES if the explorer used the key press to perform an action, NO otherwise
+- (BOOL)handleDownArrowKeyPressed;
+/// @return YES if the explorer used the key press to perform an action, NO otherwise
+- (BOOL)handleUpArrowKeyPressed;
+/// @return YES if the explorer used the key press to perform an action, NO otherwise
+- (BOOL)handleRightArrowKeyPressed;
+/// @return YES if the explorer used the key press to perform an action, NO otherwise
+- (BOOL)handleLeftArrowKeyPressed;
 
 @end
 

+ 18 - 4
Classes/ExplorerInterface/FLEXExplorerViewController.m

@@ -876,7 +876,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     } completion:nil];
 }
 
-- (void)handleDownArrowKeyPressed
+- (BOOL)handleDownArrowKeyPressed
 {
     if (self.currentMode == FLEXExplorerModeMove) {
         CGRect frame = self.selectedView.frame;
@@ -887,10 +887,14 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
         if (selectedViewIndex > 0) {
             self.selectedView = [self.viewsAtTapPoint objectAtIndex:selectedViewIndex - 1];
         }
+    } else {
+        return NO;
     }
+    
+    return YES;
 }
 
-- (void)handleUpArrowKeyPressed
+- (BOOL)handleUpArrowKeyPressed
 {
     if (self.currentMode == FLEXExplorerModeMove) {
         CGRect frame = self.selectedView.frame;
@@ -901,25 +905,35 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
         if (selectedViewIndex < self.viewsAtTapPoint.count - 1) {
             self.selectedView = [self.viewsAtTapPoint objectAtIndex:selectedViewIndex + 1];
         }
+    } else {
+        return NO;
     }
+    
+    return YES;
 }
 
-- (void)handleRightArrowKeyPressed
+- (BOOL)handleRightArrowKeyPressed
 {
     if (self.currentMode == FLEXExplorerModeMove) {
         CGRect frame = self.selectedView.frame;
         frame.origin.x += 1.0 / UIScreen.mainScreen.scale;
         self.selectedView.frame = frame;
+        return YES;
     }
+    
+    return NO;
 }
 
-- (void)handleLeftArrowKeyPressed
+- (BOOL)handleLeftArrowKeyPressed
 {
     if (self.currentMode == FLEXExplorerModeMove) {
         CGRect frame = self.selectedView.frame;
         frame.origin.x -= 1.0 / UIScreen.mainScreen.scale;
         self.selectedView.frame = frame;
+        return YES;
     }
+    
+    return NO;
 }
 
 @end

+ 21 - 20
Classes/Manager/FLEXManager+Extensibility.m

@@ -110,18 +110,14 @@
     } description:@"Toggle network history view"];
     
     [self registerSimulatorShortcutWithKey:UIKeyInputDownArrow modifiers:0 action:^{
-        if (self.isHidden) {
+        if (self.isHidden || ![self.explorerViewController handleDownArrowKeyPressed]) {
             [self tryScrollDown];
-        } else {
-            [self.explorerViewController handleDownArrowKeyPressed];
         }
     } description:@"Cycle view selection\n\t\tMove view down\n\t\tScroll down"];
     
     [self registerSimulatorShortcutWithKey:UIKeyInputUpArrow modifiers:0 action:^{
-        if (self.isHidden) {
+        if (self.isHidden || ![self.explorerViewController handleUpArrowKeyPressed]) {
             [self tryScrollUp];
-        } else {
-            [self.explorerViewController handleUpArrowKeyPressed];
         }
     } description:@"Cycle view selection\n\t\tMove view up\n\t\tScroll up"];
     
@@ -161,24 +157,29 @@
 
 #pragma mark - Private
 
+- (UIEdgeInsets)contentInsetsOfScrollView:(UIScrollView *)scrollView {
+    if (@available(iOS 11, *)) {
+        return scrollView.adjustedContentInset;
+    }
+    
+    return scrollView.contentInset;
+}
+
 - (void)tryScrollDown {
-    UIScrollView *firstScrollView = [self firstScrollView];
-    CGPoint contentOffset = firstScrollView.contentOffset;
-    CGFloat distance = floor(firstScrollView.frame.size.height / 2.0);
-    CGFloat maxContentOffsetY = firstScrollView.contentSize.height + firstScrollView.contentInset.bottom - firstScrollView.frame.size.height;
-    distance = MIN(maxContentOffsetY - firstScrollView.contentOffset.y, distance);
-    contentOffset.y += distance;
-    [firstScrollView setContentOffset:contentOffset animated:YES];
+    UIScrollView *scrollview = [self firstScrollView];
+    UIEdgeInsets insets = [self contentInsetsOfScrollView:scrollview];
+    CGPoint contentOffset = scrollview.contentOffset;
+    CGFloat maxYOffset = scrollview.contentSize.height - scrollview.bounds.size.height + insets.bottom;
+    contentOffset.y = MIN(contentOffset.y + 200, maxYOffset);
+    [scrollview setContentOffset:contentOffset animated:YES];
 }
 
 - (void)tryScrollUp {
-    UIScrollView *firstScrollView = [self firstScrollView];
-    CGPoint contentOffset = firstScrollView.contentOffset;
-    CGFloat distance = floor(firstScrollView.frame.size.height / 2.0);
-    CGFloat minContentOffsetY = -firstScrollView.contentInset.top;
-    distance = MIN(firstScrollView.contentOffset.y - minContentOffsetY, distance);
-    contentOffset.y -= distance;
-    [firstScrollView setContentOffset:contentOffset animated:YES];
+    UIScrollView *scrollview = [self firstScrollView];
+    UIEdgeInsets insets = [self contentInsetsOfScrollView:scrollview];
+    CGPoint contentOffset = scrollview.contentOffset;
+    contentOffset.y = MAX(contentOffset.y - 200, -insets.top);
+    [scrollview setContentOffset:contentOffset animated:YES];
 }
 
 - (UIScrollView *)firstScrollView {