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

Merge pull request #14 from JaviSoto/feature/lazy-window-creation

Lazily creating the FLEXWindow when it's actually needed.
Ryan Olson лет назад: 12
Родитель
Сommit
27abb6fa10
1 измененных файлов с 25 добавлено и 8 удалено
  1. 25 8
      Classes/Explorer Toolbar/FLEXManager.m

+ 25 - 8
Classes/Explorer Toolbar/FLEXManager.m

@@ -38,19 +38,36 @@
 {
     self = [super init];
     if (self) {
-        self.explorerWindow = [[FLEXWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-        self.explorerWindow.eventDelegate = self;
-        
         _userGlobalEntries = [[NSMutableArray alloc] init];
-        
-        self.explorerViewController = [[FLEXExplorerViewController alloc] init];
-        self.explorerViewController.delegate = self;
-        self.explorerWindow.rootViewController = self.explorerViewController;
-        [self.explorerWindow addSubview:self.explorerViewController.view];
     }
     return self;
 }
 
+- (FLEXWindow *)explorerWindow
+{
+    NSAssert([NSThread isMainThread], @"You must use %@ from the main thread only.", NSStringFromClass([self class]));
+    
+    if (!_explorerWindow) {
+        _explorerWindow = [[FLEXWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+        _explorerWindow.eventDelegate = self;
+
+        _explorerWindow.rootViewController = self.explorerViewController;
+        [_explorerWindow addSubview:self.explorerViewController.view];
+    }
+    
+    return _explorerWindow;
+}
+
+- (FLEXExplorerViewController *)explorerViewController
+{
+    if (!_explorerViewController) {
+        _explorerViewController = [[FLEXExplorerViewController alloc] init];
+        _explorerViewController.delegate = self;
+    }
+
+    return _explorerViewController;
+}
+
 - (void)showExplorer
 {
     self.explorerWindow.hidden = NO;