瀏覽代碼

Lazily creating the FLEXWindow when it's actually needed.

This allows users of FLEXManager to use the -registerGlobalEntryWithName:objectFutureBlock: API in a +load method of their app. Right now that creates the UIWindow object when UIKit is not ready. With this change, the window will be created the first time you call -showExplorer, which would also help a bit with launch times in apps that have FLEX because creating that object would be delayed from app launch to the first time it's used.
Javier Soto 12 年之前
父節點
當前提交
f3c53dde2c
共有 1 個文件被更改,包括 15 次插入6 次删除
  1. 15 6
      Classes/Explorer Toolbar/FLEXManager.m

+ 15 - 6
Classes/Explorer Toolbar/FLEXManager.m

@@ -38,17 +38,26 @@
 {
     self = [super init];
     if (self) {
-        self.explorerWindow = [[FLEXWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-        self.explorerWindow.eventDelegate = self;
-        
         _userGlobalEntries = [[NSMutableArray alloc] init];
+    }
+    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;
         
         self.explorerViewController = [[FLEXExplorerViewController alloc] init];
         self.explorerViewController.delegate = self;
-        self.explorerWindow.rootViewController = self.explorerViewController;
-        [self.explorerWindow addSubview:self.explorerViewController.view];
+        _explorerWindow.rootViewController = self.explorerViewController;
+        [_explorerWindow addSubview:self.explorerViewController.view];
     }
-    return self;
+    
+    return _explorerWindow;
 }
 
 - (void)showExplorer