-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMMWelcomeViewController.m
123 lines (103 loc) · 4.7 KB
/
MMWelcomeViewController.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// MMWelcomeViewController.m
// ReactNativeAsyncLoadBundle
//
// Created by Marcus on 2020/3/16.
// Copyright © 2020 Facebook. All rights reserved.
//
#import "MMWelcomeViewController.h"
#import "MMSyncReactNativeContainerViewController.h"
#import "MMAsyncGuideViewController.h"
#import "Masonry.h"
#import "MMTimeRecordUtil.h"
@interface MMWelcomeViewController ()
@end
@implementation MMWelcomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationItem setTitle:@"Welcome"];
CGRect screenRect = [[UIScreen mainScreen] bounds];
UILabel *labelTips = [[UILabel alloc] init];
labelTips.text = @"There are two ways to start an activity with react naitve in the demo: one as SYNC, the other as ASYNC. It is same with the offical reference implementation when using SYNC. As for ASYNC, it will start a general activity, which will load a common bundle file, after that it will start a custom activity, which will only load the differential bundle file. The load time of react view will display by log and toast.";
labelTips.font = [UIFont systemFontOfSize:18];
labelTips.lineBreakMode = NSLineBreakByWordWrapping;
labelTips.numberOfLines = 0;
[self.view addSubview:labelTips];
[labelTips mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@240);
make.left.equalTo(self.view).offset(20);
make.right.equalTo(self.view).offset(-20);
make.centerY.equalTo(self.view.mas_top).offset(screenRect.size.height/5 + 20);
make.centerX.mas_equalTo(self.view);
}];
UILabel *labelNotice = [[UILabel alloc] init];
labelNotice.text = @"NOTICE: If you want to get the load time accurately, you should restart the app before clicking one of the bottom two buttons.";
labelNotice.textColor = UIColor.redColor;
labelNotice.lineBreakMode = NSLineBreakByWordWrapping;
labelNotice.numberOfLines = 0;
[self.view addSubview:labelNotice];
[labelNotice mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@100);
make.left.equalTo(self.view).offset(20);
make.right.equalTo(self.view).offset(-20);
make.centerY.equalTo(self.view.mas_top).offset(screenRect.size.height/5*2);
make.centerX.equalTo(self.view);
}];
UIButton *btnSync = [[UIButton alloc] init];
[btnSync setTitle:@"Sync Load RN Bundle" forState:UIControlStateNormal];
[btnSync setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnSync setBackgroundColor:[UIColor lightGrayColor]];
[btnSync setTag: 1];
[btnSync addTarget:self
action:@selector(btnClickListener:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnSync];
[btnSync mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(20);
make.right.equalTo(self.view).offset(-20);
make.height.equalTo(@60);
make.centerY.equalTo(self.view.mas_top).offset(screenRect.size.height/5*3);
make.centerX.mas_equalTo(self.view);
}];
UIButton *btnAsync = [[UIButton alloc] init];
[btnAsync setTitle:@"Async Load RN Bundle" forState:UIControlStateNormal];
[btnAsync setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnAsync setBackgroundColor:[UIColor lightGrayColor]];
[btnAsync setTag: 2];
[btnAsync addTarget:self
action:@selector(btnClickListener:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnAsync];
[btnAsync mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(20);
make.right.equalTo(self.view).offset(-20);
make.height.equalTo(@60);
make.centerY.equalTo(self.view.mas_top).offset(screenRect.size.height/5*4);
make.centerX.equalTo(self.view);
}];
}
-(void)btnClickListener:(UIButton *) button{
if(button.tag == 1){
// sync Button
NSLog(@"Sync Button Clicked.");
MMSyncReactNativeContainerViewController *controller = [[MMSyncReactNativeContainerViewController alloc] init];
[self.navigationController pushViewController:controller animated:NO];
[[MMTimeRecordUtil getInstance] setStartTime:@"ViewAction"];
}else if(button.tag == 2){
// async Button
NSLog(@"Async Button Clicked.");
MMAsyncGuideViewController *controller = [[MMAsyncGuideViewController alloc] init];
[self.navigationController pushViewController:controller animated:NO];
}else {
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end