-
Notifications
You must be signed in to change notification settings - Fork 68
/
AppDelegate.m
67 lines (53 loc) · 2.46 KB
/
AppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Creates the React Native bridge and adds a custom menu item to the dev menu,
// then opens the main React Native view.
#import <React/RCTBundleURLProvider.h>
#import <React/RCTDevMenu.h>
#import <React/RCTRootView.h>
#import "AppDelegate.h"
#import "ExampleView.h"
@implementation AppDelegate
{
UINavigationController *navigationController;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.reactBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTDevMenuItem *devMenuItem = [RCTDevMenuItem buttonItemWithTitle:@"Custom menu item"
handler:^{
NSLog(@"Custom menu item clicked!");
}];
[self.reactBridge.devMenu addItem:devMenuItem];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.reactBridge
moduleName:@"ActivityDemoComponent"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
- (void) navigateToExampleView
{
ExampleView *viewController = [[ExampleView alloc] initWithNibName:@"ExampleView" bundle:nil];
[navigationController pushViewController:viewController animated:YES];
}
- (void) navigateBack
{
[navigationController popViewControllerAnimated:YES];
}
- (void) callJavaScript
{
[self.reactBridge enqueueJSCall:@"JavaScriptVisibleToJava"
method:@"alert"
args:@[@"Hello, JavaScript!"]
completion:nil];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"
fallbackResource:nil];
return jsCodeLocation;
}
@end