Parcourir la source

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 il y a 12 ans
Parent
commit
f3c53dde2c
1 fichiers modifiés avec 15 ajouts et 6 suppressions
  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