Last active
August 29, 2015 14:21
-
-
Save revskill10/82fbef995e1c2fab5115 to your computer and use it in GitHub Desktop.
Beginning React-Native ref: http://qiita.com/checkraiser/items/1967ff7e78cea50f753a
This file contains hidden or 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
| OS X - This repo only contains the iOS implementation right now, and Xcode only runs on Mac. | |
| New to Xcode? Download it from the Mac App Store. | |
| Homebrew is the recommended way to install node, watchman, and flow. | |
| brew install node. | |
| brew install --HEAD watchman. We recommend installing watchman, otherwise you might hit a node file watching bug. | |
| brew install flow. If you want to use flow. |
This file contains hidden or 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
| npm install -g react-native-cli | |
| react-native init AwesomeProject |
This file contains hidden or 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
| #import "AppDelegate.h" | |
| #import "MyViewController.h" | |
| @implementation AppDelegate | |
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
| { | |
| //NSURL *jsCodeLocation; | |
| // Loading JavaScript code - uncomment the one you want. | |
| // OPTION 1 | |
| // Load from development server. Start the server from the repository root: | |
| // | |
| // $ npm start | |
| // | |
| // To run on device, change `localhost` to the IP address of your computer, and make sure your computer and | |
| // iOS device are on the same Wi-Fi network. | |
| //jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"]; | |
| // OPTION 2 | |
| // Load from pre-bundled file on disk. To re-generate the static bundle, run | |
| // | |
| // $ curl http://localhost:8081/index.ios.bundle -o main.jsbundle | |
| // | |
| // and uncomment the next following line | |
| self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
| //UIViewController *rootViewController = [[UIViewController alloc] init]; | |
| MyViewController *rootViewController = [[MyViewController alloc] init]; | |
| rootViewController.launchOptions = launchOptions; | |
| self.window.rootViewController = rootViewController; | |
| [self.window makeKeyAndVisible]; | |
| return YES; | |
| } | |
| @end |
This file contains hidden or 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
| Open AwesomeProject.xcodeproj and hit run in Xcode | |
| Open index.ios.js in your text editor of choice and edit some lines | |
| Hit cmd+R (twice) in your iOS simulator to reload the app and see your change! |
This file contains hidden or 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
| AwesomeProject.xcodeproj/ | |
| Podfile | |
| iOS/ | |
| index.ios.js | |
| node_modules/ | |
| package.json |
This file contains hidden or 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
| // Creating the Canvas | |
| self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
| // Creating the Brush | |
| MyViewController *rootViewController = [[MyViewController alloc] init]; | |
| rootViewController.launchOptions = launchOptions; | |
| // Make the Canvas use the Brush | |
| self.window.rootViewController = rootViewController; | |
| [self.window makeKeyAndVisible]; | |
| return YES; |
This file contains hidden or 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
| RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"AdmobTest" launchOptions:self.launchOptions]; | |
| rootView.frame = CGRectMake(0, 50, viewRect.size.width, viewRect.size.height - 50); | |
| [self.view addSubview:rootView]; |
This file contains hidden or 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
| NSURL *jsCodeLocation; | |
| jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
| RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"SampleApp" launchOptions:self.launchOptions]; |
This file contains hidden or 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
| `AppRegistry.registerComponent('SampleApp', () => SampleApp);` |
This file contains hidden or 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
| Create new react native view, and put it inside a `ViewController`, style the view with backgroundColor blue. |
This file contains hidden or 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
| // MyViewController.h | |
| #import <UIKit/UIKit.h> | |
| #import "RCTRootView.h" | |
| @interface MyViewController : UIViewController | |
| @property (weak, nonatomic) NSDictionary *launchOptions; | |
| @end | |
| // MyViewController.m | |
| #import "MyViewController.h" | |
| @implementation MyViewController | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| NSURL *jsCodeLocation; | |
| jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
| RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"AdmobTest" launchOptions:self.launchOptions]; | |
| rootView.frame = CGRectMake(0, 50, viewRect.size.width, viewRect.size.height - 50); | |
| [self.view addSubview:rootView]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment