FLEXManager.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // FLEXManager.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 4/4/14.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXManager.h"
  9. #import "FLEXExplorerViewController.h"
  10. #import "FLEXWindow.h"
  11. #import "FLEXGlobalsTableViewControllerEntry.h"
  12. #import "FLEXObjectExplorerFactory.h"
  13. #import "FLEXObjectExplorerViewController.h"
  14. @interface FLEXManager () <FLEXWindowEventDelegate, FLEXExplorerViewControllerDelegate>
  15. @property (nonatomic, strong) FLEXWindow *explorerWindow;
  16. @property (nonatomic, strong) FLEXExplorerViewController *explorerViewController;
  17. @property (nonatomic, readonly, strong) NSMutableArray *userGlobalEntries;
  18. @end
  19. @implementation FLEXManager
  20. + (instancetype)sharedManager
  21. {
  22. static FLEXManager *sharedManager = nil;
  23. static dispatch_once_t onceToken;
  24. dispatch_once(&onceToken, ^{
  25. sharedManager = [[[self class] alloc] init];
  26. });
  27. return sharedManager;
  28. }
  29. - (instancetype)init
  30. {
  31. self = [super init];
  32. if (self) {
  33. self.explorerWindow = [[FLEXWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  34. self.explorerWindow.eventDelegate = self;
  35. self.explorerViewController = [[FLEXExplorerViewController alloc] init];
  36. self.explorerViewController.delegate = self;
  37. self.explorerWindow.rootViewController = self.explorerViewController;
  38. [self.explorerWindow addSubview:self.explorerViewController.view];
  39. }
  40. return self;
  41. }
  42. - (void)showExplorer
  43. {
  44. self.explorerWindow.hidden = NO;
  45. }
  46. - (void)hideExplorer
  47. {
  48. self.explorerWindow.hidden = YES;
  49. }
  50. - (BOOL)isHidden
  51. {
  52. return self.explorerWindow.isHidden;
  53. }
  54. #pragma mark - FLEXWindowEventDelegate
  55. - (BOOL)shouldHandleTouchAtPoint:(CGPoint)pointInWindow
  56. {
  57. // Ask the explorer view controller
  58. return [self.explorerViewController shouldReceiveTouchAtWindowPoint:pointInWindow];
  59. }
  60. #pragma mark - FLEXExplorerViewControllerDelegate
  61. - (void)explorerViewControllerDidFinish:(FLEXExplorerViewController *)explorerViewController
  62. {
  63. [self hideExplorer];
  64. }
  65. #pragma mark - Extensions
  66. - (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock
  67. {
  68. NSParameterAssert(entryName);
  69. NSParameterAssert(objectFutureBlock);
  70. NSAssert([NSThread isMainThread], @"This method must be called from the main thread.");
  71. entryName = entryName.copy;
  72. FLEXGlobalsTableViewControllerEntry *entry = [FLEXGlobalsTableViewControllerEntry entryWithNameFuture:^NSString *{
  73. return entryName;
  74. } viewControllerFuture:^UIViewController *{
  75. return [FLEXObjectExplorerFactory explorerViewControllerForObject:objectFutureBlock()];
  76. }];
  77. [self.userGlobalEntries addObject:entry];
  78. }
  79. @end