소스 검색

Add swipe gesture to object explorer screen

Gesture allows you to swipe right or left to go up or down the class hierarchy without having to reach up to the top of the screen.

This commit also moves some methods around (nonemptySections, sectionHasActions:)
Tanner Bennett 6 년 전
부모
커밋
65e5bee4e3
3개의 변경된 파일62개의 추가작업 그리고 16개의 파일을 삭제
  1. 1 1
      Classes/Core/FLEXTableViewController.h
  2. 10 0
      Classes/Core/FLEXTableViewController.m
  3. 51 15
      Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

+ 1 - 1
Classes/Core/FLEXTableViewController.h

@@ -84,7 +84,7 @@ extern CGFloat const kFLEXDebounceForExpensiveIO;
 
 
 /// If using the scope bar, self.searchController.searchBar.selectedScopeButtonIndex.
 /// If using the scope bar, self.searchController.searchBar.selectedScopeButtonIndex.
 /// Otherwise, this is the selected index of the carousel, or NSNotFound if using neither.
 /// Otherwise, this is the selected index of the carousel, or NSNotFound if using neither.
-@property (nonatomic, readonly) NSInteger selectedScope;
+@property (nonatomic) NSInteger selectedScope;
 /// self.searchController.searchBar.text
 /// self.searchController.searchBar.text
 @property (nonatomic, readonly) NSString *searchText;
 @property (nonatomic, readonly) NSString *searchText;
 
 

+ 10 - 0
Classes/Core/FLEXTableViewController.m

@@ -122,6 +122,16 @@ CGFloat const kFLEXDebounceForExpensiveIO = 0.5;
     }
     }
 }
 }
 
 
+- (void)setSelectedScope:(NSInteger)selectedScope {
+    if (self.searchController.searchBar.showsScopeBar) {
+        self.searchController.searchBar.selectedScopeButtonIndex = selectedScope;
+    } else if (self.showsCarousel) {
+        self.carousel.selectedIndex = selectedScope;
+    }
+
+    [self updateSearchResults:self.searchText];
+}
+
 - (NSString *)searchText {
 - (NSString *)searchText {
     return self.searchController.searchBar.text;
     return self.searchController.searchBar.text;
 }
 }

+ 51 - 15
Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

@@ -23,7 +23,7 @@
 #import <objc/runtime.h>
 #import <objc/runtime.h>
 
 
 #pragma mark - Private properties
 #pragma mark - Private properties
-@interface FLEXObjectExplorerViewController ()
+@interface FLEXObjectExplorerViewController () <UIGestureRecognizerDelegate>
 
 
 @property (nonatomic, copy) NSString *filterText;
 @property (nonatomic, copy) NSString *filterText;
 /// Every section in the table view, regardless of whether or not a section is empty.
 /// Every section in the table view, regardless of whether or not a section is empty.
@@ -121,6 +121,20 @@
     ];
     ];
     UIMenuController.sharedMenuController.menuItems = @[copyObjectAddress];
     UIMenuController.sharedMenuController.menuItems = @[copyObjectAddress];
     [UIMenuController.sharedMenuController update];
     [UIMenuController.sharedMenuController update];
+
+    // Swipe gestures to swipe between classes in the hierarchy
+    UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]
+        initWithTarget:self action:@selector(handleSwipeGesture:)
+    ];
+    leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
+    UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]
+        initWithTarget:self action:@selector(handleSwipeGesture:)
+    ];
+    rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
+    leftSwipe.delegate = self;
+    rightSwipe.delegate = self;
+    [self.tableView addGestureRecognizer:leftSwipe];
+    [self.tableView addGestureRecognizer:rightSwipe];
 }
 }
 
 
 - (void)viewWillAppear:(BOOL)animated
 - (void)viewWillAppear:(BOOL)animated
@@ -193,6 +207,42 @@
     return sections.copy;
     return sections.copy;
 }
 }
 
 
+- (NSArray<FLEXExplorerSection *> *)nonemptySections
+{
+    return [self.allSections flex_filtered:^BOOL(FLEXExplorerSection *section, NSUInteger idx) {
+        return section.numberOfRows > 0;
+    }];
+}
+
+- (BOOL)sectionHasActions:(NSInteger)section
+{
+    return self.sections[section] == self.descriptionSection;
+}
+
+- (void)handleSwipeGesture:(UISwipeGestureRecognizer *)gesture {
+    if (gesture.state == UIGestureRecognizerStateEnded) {
+        switch (gesture.direction) {
+            case UISwipeGestureRecognizerDirectionRight:
+                if (self.selectedScope > 0) {
+                    self.selectedScope -= 1;
+                }
+                break;
+            case UISwipeGestureRecognizerDirectionLeft:
+                if (self.selectedScope != self.explorer.classHierarchy.count - 1) {
+                    self.selectedScope += 1;
+                }
+                break;
+
+            default:
+                break;
+        }
+    }
+}
+
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)g1 shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)g2 {
+    return [g2 class] == [UIPanGestureRecognizer class];
+}
+
 #pragma mark - Description
 #pragma mark - Description
 
 
 - (BOOL)shouldShowDescription
 - (BOOL)shouldShowDescription
@@ -256,20 +306,6 @@
     }
     }
 }
 }
 
 
-#pragma mark - Private
-
-- (NSArray<FLEXExplorerSection *> *)nonemptySections
-{
-    return [self.allSections flex_filtered:^BOOL(FLEXExplorerSection *section, NSUInteger idx) {
-        return section.numberOfRows > 0;
-    }];
-}
-
-- (BOOL)sectionHasActions:(NSInteger)section
-{
-    return self.sections[section] == self.descriptionSection;
-}
-
 
 
 #pragma mark - UITableViewDataSource
 #pragma mark - UITableViewDataSource