Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Initialization] Decouple script loading and environment setup from the root view #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Examples/Movies/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTRootViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
RCTRootView *rootView = [[RCTRootView alloc] init];

// Loading JavaScript code - uncomment the one you want.

Expand All @@ -30,13 +29,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// and uncomment the next following line
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

rootView.scriptURL = jsCodeLocation;
rootView.moduleName = @"MoviesApp";
RCTRootViewController *viewController = [[RCTRootViewController alloc] init];
viewController.moduleName = @"MoviesApp";
viewController.scriptURL = jsCodeLocation;

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
12 changes: 5 additions & 7 deletions Examples/TicTacToe/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTRootViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
RCTRootView *rootView = [[RCTRootView alloc] init];

// Loading JavaScript code - uncomment the one you want.

Expand All @@ -30,13 +29,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// and uncomment the next following line
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

rootView.scriptURL = jsCodeLocation;
rootView.moduleName = @"TicTacToeApp";
RCTRootViewController *viewController = [[RCTRootViewController alloc] init];
viewController.moduleName = @"TicTacToeApp";
viewController.scriptURL = jsCodeLocation;

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
12 changes: 5 additions & 7 deletions Examples/UIExplorer/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTRootViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
RCTRootView *rootView = [[RCTRootView alloc] init];

// Loading JavaScript code - uncomment the one you want.

Expand All @@ -30,13 +29,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// and uncomment the next following line
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

rootView.scriptURL = jsCodeLocation;
rootView.moduleName = @"UIExplorerApp";
RCTRootViewController *viewController = [[RCTRootViewController alloc] init];
viewController.moduleName = @"UIExplorerApp";
viewController.scriptURL = jsCodeLocation;

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
12 changes: 5 additions & 7 deletions IntegrationTests/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTRootViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
RCTRootView *rootView = [[RCTRootView alloc] init];

// Loading JavaScript code - uncomment the one you want.

Expand All @@ -30,13 +29,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// and uncomment the next following line
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

rootView.scriptURL = jsCodeLocation;
rootView.moduleName = @"IntegrationTestsApp";
RCTRootViewController *viewController = [[RCTRootViewController alloc] init];
viewController.moduleName = @"IntegrationTestsApp";
viewController.scriptURL = jsCodeLocation;

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
15 changes: 7 additions & 8 deletions Libraries/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "RCTTestRunner.h"

#import "RCTRedBox.h"
#import "RCTRootView.h"
#import "RCTRootViewController.h"
#import "RCTTestModule.h"
#import "RCTUtils.h"

Expand Down Expand Up @@ -34,15 +34,14 @@ - (void)runTest:(NSString *)moduleName initialProps:(NSDictionary *)initialProps
- (void)runTest:(NSString *)moduleName initialProps:(NSDictionary *)initialProps expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
{
RCTTestModule *testModule = [[RCTTestModule alloc] init];
RCTRootView *rootView = [[RCTRootView alloc] init];
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
vc.view = rootView;
rootView.moduleProvider = ^(void){
RCTRootViewController *rootViewController = [[RCTRootViewController alloc] init];
[[UIApplication sharedApplication].delegate window].rootViewController = rootViewController;
rootViewController.moduleProvider = ^(void){
return @[testModule];
};
rootView.moduleName = moduleName;
rootView.initialProperties = initialProps;
rootView.scriptURL = [NSURL URLWithString:_script];
rootViewController.moduleName = moduleName;
rootViewController.initialProperties = initialProps;
rootViewController.scriptURL = [NSURL URLWithString:_script];

NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
NSString *error = [[RCTRedBox sharedInstance] currentErrorMessage];
Expand Down
2 changes: 1 addition & 1 deletion ReactKit/Base/RCTRedBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (void)dismiss

- (void)reload
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTReloadNotification" object:nil userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:self];
[self dismiss];
}

Expand Down
46 changes: 0 additions & 46 deletions ReactKit/Base/RCTRootView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,6 @@

#import <UIKit/UIKit.h>

#import "RCTBridge.h"

@interface RCTRootView : UIView

/**
* The URL of the bundled application script (required).
* Setting this will clear the view contents, and trigger
* an asynchronous load/download and execution of the script.
*/
@property (nonatomic, strong) NSURL *scriptURL;

/**
* The name of the JavaScript module to execute within the
* specified scriptURL (required). Setting this will not have
* any immediate effect, but it must be done prior to loading
* the script.
*/
@property (nonatomic, copy) NSString *moduleName;

/**
* A block that returns an array of pre-allocated modules. These
* modules will take precedence over any automatically registered
* modules of the same name.
*/
@property (nonatomic, copy) RCTBridgeModuleProviderBlock moduleProvider;

/**
* The default properties to apply to the view when the script bundle
* is first loaded. Defaults to nil/empty.
*/
@property (nonatomic, copy) NSDictionary *initialProperties;

/**
* The class of the RCTJavaScriptExecutor to use with this view.
* If not specified, it will default to using RCTContextExecutor.
* Changes will take effect next time the bundle is reloaded.
*/
@property (nonatomic, strong) Class executorClass;

/**
* Reload this root view, or all root views, respectively.
*/
- (void)reload;
+ (void)reloadAll;

- (void)startOrResetInteractionTiming;
- (NSDictionary *)endAndResetInteractionTiming;

@end
Loading