Last active
January 7, 2016 21:49
-
-
Save jemise111/b655cdc4a95c8eb44cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ReactNativeViewObjC.m | |
// | |
#import "ReactNativeViewObjC.h" | |
#import "RCTRootView.h" | |
@implementation ReactNativeViewObjC | |
-(void) initializeReactView { | |
BOOL REACT_DEV_MODE = NO; | |
if (self.data == nil) { | |
self.data = [@{} mutableCopy]; | |
} | |
// this is a good place to pass configuration variables | |
[self.data setValuesForKeysWithDictionary:@{ | |
@"DEV_MODE" : [NSNumber numberWithBool:REACT_DEV_MODE], | |
@"API_KEY" : @"ABCDEF123456", | |
@"AUTHORIZATION_TOKEN" : @"a8b6de25b5bf481824c9c4173c56231a" | |
}]; | |
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; | |
if (!REACT_DEV_MODE) { | |
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
} | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation | |
moduleName:@"ReactNativeExample" | |
initialProperties:self.data | |
launchOptions:nil]; | |
rootView.translatesAutoresizingMaskIntoConstraints = NO; | |
[self addSubview:rootView]; | |
NSDictionary *views = @{@"rootView": rootView}; | |
NSArray *constraints = @[]; | |
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[rootView]-0-|" options:0 metrics:nil views:views]]; | |
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[rootView]-0-|" options:0 metrics:nil views:views]]; | |
[self addConstraints:constraints]; | |
[self layoutIfNeeded]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment