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

Refactor presentation/dismissal code from toolbar

- Now expects UINavigationControllers to be presented
- The only view controller to add it's own done buttons now is the hierarchy screen because it needs to pass data back to the explorer upon dismissal
- Automatically adds a Done button to the navigationItem of the topViewController of presented navigation controllers if a button is not already present
- Remove FLEXGlobalsTableViewControllerDelegate, etc, and like methods
- Adopt iOS 13 APIs for detecting modal sheet dismissal by dragging
Tanner Bennett лет назад: 6
Родитель
Сommit
3fdaead2f7

+ 1 - 1
Classes/ExplorerInterface/FLEXExplorerViewController.h

@@ -22,7 +22,7 @@
 ///
 ///
 /// If a tool is already presented, this method simply dismisses it and calls the completion block.
 /// If a tool is already presented, this method simply dismisses it and calls the completion block.
 /// If no tool is presented, @code future() @endcode is presented and the completion block is called.
 /// If no tool is presented, @code future() @endcode is presented and the completion block is called.
-- (void)toggleToolWithViewControllerProvider:(UIViewController *(^)(void))future completion:(void(^)(void))completion;
+- (void)toggleToolWithViewControllerProvider:(UINavigationController *(^)(void))future completion:(void(^)(void))completion;
 
 
 // Keyboard shortcut helpers
 // Keyboard shortcut helpers
 
 

+ 28 - 18
Classes/ExplorerInterface/FLEXExplorerViewController.m

@@ -24,7 +24,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     FLEXExplorerModeMove
     FLEXExplorerModeMove
 };
 };
 
 
-@interface FLEXExplorerViewController () <FLEXHierarchyDelegate, FLEXGlobalsTableViewControllerDelegate>
+@interface FLEXExplorerViewController () <FLEXHierarchyDelegate, UIAdaptivePresentationControllerDelegate>
 
 
 @property (nonatomic) FLEXExplorerToolbar *explorerToolbar;
 @property (nonatomic) FLEXExplorerToolbar *explorerToolbar;
 
 
@@ -494,9 +494,8 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 - (void)handleToolbarDetailsTapGesture:(UITapGestureRecognizer *)tapGR
 - (void)handleToolbarDetailsTapGesture:(UITapGestureRecognizer *)tapGR
 {
 {
     if (tapGR.state == UIGestureRecognizerStateRecognized && self.selectedView) {
     if (tapGR.state == UIGestureRecognizerStateRecognized && self.selectedView) {
-        FLEXObjectExplorerViewController *selectedViewExplorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:self.selectedView];
-        selectedViewExplorer.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(selectedViewExplorerFinished:)];
-        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:selectedViewExplorer];
+        UIViewController *topStackVC = [FLEXObjectExplorerFactory explorerViewControllerForObject:self.selectedView];
+        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:topStackVC];
         [self makeKeyAndPresentViewController:navigationController animated:YES completion:nil];
         [self makeKeyAndPresentViewController:navigationController animated:YES completion:nil];
     }
     }
 }
 }
@@ -729,25 +728,21 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 }
 }
 
 
 
 
-#pragma mark - FLEXGlobalsViewControllerDelegate
+#pragma mark - Modal Dismissal
 
 
-- (void)globalsViewControllerDidFinish:(FLEXGlobalsTableViewController *)globalsViewController
+- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
 {
 {
-    [self resignKeyAndDismissViewControllerAnimated:YES completion:nil];
+    [self presentedViewControllerDidDismiss];
 }
 }
 
 
-
-#pragma mark - FLEXObjectExplorerViewController Done Action
-
-- (void)selectedViewExplorerFinished:(id)sender
+- (void)presentedViewControllerDidDismiss
 {
 {
     [self resignKeyAndDismissViewControllerAnimated:YES completion:nil];
     [self resignKeyAndDismissViewControllerAnimated:YES completion:nil];
 }
 }
 
 
-
 #pragma mark - Modal Presentation and Window Management
 #pragma mark - Modal Presentation and Window Management
 
 
-- (void)makeKeyAndPresentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^)(void))completion
+- (void)makeKeyAndPresentViewController:(UINavigationController *)toPresent animated:(BOOL)animated completion:(void (^)(void))completion
 {
 {
     // Save the current key window so we can restore it following dismissal.
     // Save the current key window so we can restore it following dismissal.
     self.previousKeyWindow = UIApplication.sharedApplication.keyWindow;
     self.previousKeyWindow = UIApplication.sharedApplication.keyWindow;
@@ -770,8 +765,24 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     UIMenuController.sharedMenuController.menuItems = @[copyObjectAddress];
     UIMenuController.sharedMenuController.menuItems = @[copyObjectAddress];
     [UIMenuController.sharedMenuController update];
     [UIMenuController.sharedMenuController update];
     
     
+    // Add the "Done" button to the navigation controller's view controller if it doesn't have one
+    // (the hierarchy screen adds it's own done button in order to pass data between us)
+    if (!toPresent.topViewController.navigationItem.rightBarButtonItem) {
+        toPresent.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
+            initWithBarButtonSystemItem:UIBarButtonSystemItemDone
+            target:self
+            action:@selector(presentedViewControllerDidDismiss)
+        ];
+    }
+    
+    // Make myself the delegate for sheets presented modally so we can do the
+    // proper cleanup when sheets are dragged to dismiss without the done button
+    if (@available(iOS 13, *)) {
+        toPresent.presentationController.delegate = self;
+    }
+    
     // Show the view controller.
     // Show the view controller.
-    [self presentViewController:viewController animated:animated completion:completion];
+    [self presentViewController:toPresent animated:animated completion:completion];
 }
 }
 
 
 - (void)resignKeyAndDismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion
 - (void)resignKeyAndDismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion
@@ -799,7 +810,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     return self.previousKeyWindow != nil;
     return self.previousKeyWindow != nil;
 }
 }
 
 
-- (void)toggleToolWithViewControllerProvider:(UIViewController *(^)(void))future completion:(void(^)(void))completion
+- (void)toggleToolWithViewControllerProvider:(UINavigationController *(^)(void))future completion:(void(^)(void))completion
 {
 {
     if (self.presentedViewController) {
     if (self.presentedViewController) {
         [self resignKeyAndDismissViewControllerAnimated:YES completion:completion];
         [self resignKeyAndDismissViewControllerAnimated:YES completion:completion];
@@ -835,7 +846,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 
 - (void)toggleViewsToolWithCompletion:(void(^)(void))completion
 - (void)toggleViewsToolWithCompletion:(void(^)(void))completion
 {
 {
-    [self toggleToolWithViewControllerProvider:^UIViewController *{
+    [self toggleToolWithViewControllerProvider:^UINavigationController *{
         if (self.selectedView) {
         if (self.selectedView) {
             return [FLEXHierarchyViewController
             return [FLEXHierarchyViewController
                 delegate:self
                 delegate:self
@@ -854,9 +865,8 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 
 - (void)toggleMenuTool
 - (void)toggleMenuTool
 {
 {
-    [self toggleToolWithViewControllerProvider:^UIViewController *{
+    [self toggleToolWithViewControllerProvider:^UINavigationController *{
         FLEXGlobalsTableViewController *globalsViewController = [FLEXGlobalsTableViewController new];
         FLEXGlobalsTableViewController *globalsViewController = [FLEXGlobalsTableViewController new];
-        globalsViewController.delegate = self;
         [FLEXGlobalsTableViewController setApplicationWindow:[UIApplication.sharedApplication keyWindow]];
         [FLEXGlobalsTableViewController setApplicationWindow:[UIApplication.sharedApplication keyWindow]];
         return [[UINavigationController alloc] initWithRootViewController:globalsViewController];
         return [[UINavigationController alloc] initWithRootViewController:globalsViewController];
     } completion:nil];
     } completion:nil];

+ 0 - 8
Classes/GlobalStateExplorers/Globals/FLEXGlobalsTableViewController.h

@@ -25,16 +25,8 @@ typedef NS_ENUM(NSUInteger, FLEXGlobalsSectionKind) {
 
 
 @interface FLEXGlobalsTableViewController : FLEXTableViewController
 @interface FLEXGlobalsTableViewController : FLEXTableViewController
 
 
-@property (nonatomic, weak) id <FLEXGlobalsTableViewControllerDelegate> delegate;
-
 /// We pretend that one of the app's windows is still the key window, even though the explorer window may have become key.
 /// We pretend that one of the app's windows is still the key window, even though the explorer window may have become key.
 /// We want to display debug state about the application, not about this tool.
 /// We want to display debug state about the application, not about this tool.
 + (void)setApplicationWindow:(UIWindow *)applicationWindow;
 + (void)setApplicationWindow:(UIWindow *)applicationWindow;
 
 
 @end
 @end
-
-@protocol FLEXGlobalsTableViewControllerDelegate <NSObject>
-
-- (void)globalsViewControllerDidFinish:(FLEXGlobalsTableViewController *)globalsViewController;
-
-@end

+ 0 - 12
Classes/GlobalStateExplorers/Globals/FLEXGlobalsTableViewController.m

@@ -169,13 +169,6 @@ static __weak UIWindow *s_applicationWindow = nil;
         _allSections = [_allSections arrayByAddingObject:custom];
         _allSections = [_allSections arrayByAddingObject:custom];
     }
     }
     self.sections = self.allSections;
     self.sections = self.allSections;
-
-    // Done button
-    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
-        initWithBarButtonSystemItem:UIBarButtonSystemItemDone
-        target:self
-        action:@selector(donePressed:)
-    ];
 }
 }
 
 
 #pragma mark - Search Bar
 #pragma mark - Search Bar
@@ -197,11 +190,6 @@ static __weak UIWindow *s_applicationWindow = nil;
 
 
 #pragma mark - Private
 #pragma mark - Private
 
 
-- (void)donePressed:(id)sender
-{
-    [self.delegate globalsViewControllerDidFinish:self];
-}
-
 - (NSArray<FLEXGlobalsSection *> *)nonemptySections
 - (NSArray<FLEXGlobalsSection *> *)nonemptySections
 {
 {
     return [self.allSections flex_filtered:^BOOL(FLEXTableViewSection *section, NSUInteger idx) {
     return [self.allSections flex_filtered:^BOOL(FLEXTableViewSection *section, NSUInteger idx) {

+ 2 - 1
Classes/ViewHierarchy/FLEXHierarchyViewController.m

@@ -84,7 +84,8 @@ typedef NS_ENUM(NSUInteger, FLEXHierarchyViewMode) {
 }
 }
 
 
 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
-    // Done button
+    // Done button: manually added here because the hierarhcy screens need to actually pass
+    // data back to the explorer view controller so that it can highlight selected views
     viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
     viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
         initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed)
         initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed)
     ];
     ];