FLEXNavigationController.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // FLEXNavigationController.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 1/30/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXNavigationController.h"
  9. @interface UINavigationController (Private) <UIGestureRecognizerDelegate>
  10. - (void)_gestureRecognizedInteractiveHide:(UIGestureRecognizer *)sender;
  11. @end
  12. @interface UIPanGestureRecognizer (Private)
  13. - (void)_setDelegate:(id)delegate;
  14. @end
  15. @interface FLEXNavigationController ()
  16. @property (nonatomic, readonly) BOOL toolbarWasHidden;
  17. @property (nonatomic) BOOL waitingToAddTab;
  18. @end
  19. @implementation FLEXNavigationController
  20. + (instancetype)withRootViewController:(UIViewController *)rootVC {
  21. return [[self alloc] initWithRootViewController:rootVC];
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.waitingToAddTab = YES;
  26. }
  27. - (void)_gestureRecognizedInteractiveHide:(UIPanGestureRecognizer *)sender {
  28. if (sender.state == UIGestureRecognizerStateRecognized) {
  29. BOOL show = self.topViewController.toolbarItems.count;
  30. CGFloat yTranslation = [sender translationInView:self.view].y;
  31. CGFloat yVelocity = [sender velocityInView:self.view].y;
  32. if (yVelocity > 2000) {
  33. [self setToolbarHidden:YES animated:YES];
  34. } else if (show && yTranslation > 20 && yVelocity > 250) {
  35. [self setToolbarHidden:NO animated:YES];
  36. } else if (yTranslation < -20) {
  37. [self setToolbarHidden:YES animated:YES];
  38. }
  39. }
  40. }
  41. @end